import_importlib leaks module attr sets
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Python
- Star
- 77.2k
- Fork
- 35.9k
- Chỉ số merge pull request
- Chỉ số pull request đang chờ
Mô tả
Bug report
Bug description:
Our CI (https://github.com/facebookincubator/cinder/actions/runs/29382592631/job/87249270535) was failing on test_pickle and test_pickletool with:
PicklingError: Can't pickle
<class 'importlib._bootstrap.BuiltinImporter'>:
it's not the same object as
importlib._bootstrap.BuiltinImporter
I believe this is happening because we run multiple test modules in the same interpreter, so the following sequence happens:
test_importlib.util.import_importlib()imports a source copy ofimportlibwhile blocking_frozen_importlib. During this import,importlib._bootstrap._setup()initializes import metadata on existing built-in modules. Ifbuiltins.__loader__orbuiltins.__spec__was originally absent, the source copy installs its ownBuiltinImporter.- Although
import_fresh_module()restoressys.modules, it does not restore attributes mutated on existing module objects. Consequently,builtins.__loader__continues to reference the temporary sourceBuiltinImporter, whileimportlib._bootstrap.BuiltinImporterresolves to the restored frozen class. - Pickle serializes classes by module and qualified name and verifies that the resolved global is the same object. The two
BuiltinImporterclass objects therefore cause the identity check to fail.
To fix this we need to snapshot __loader__ and __spec__ before importing importlib and then restore them to their original values after.
CPython versions tested on:
CPython main branch
Operating systems tested on:
macOS
Linked PRs
- gh-154276
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu với test_importlib.util.import_importlib(), sau đó tái hiện lỗi trong test_pickle và test_pickletool. Theo dõi cách việc import importlib tạm thời thay đổi builtins.loader và builtins.spec; hoàn tất khi các giá trị ban đầu được khôi phục và cả hai bài kiểm thử đều vượt qua mà không có PicklingError. Một PR được liên kết, gh-154276, cho biết công việc đã được tiến hành.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- python
- Lĩnh vực
- backend, testing-qa
- Loại issue
- Lỗi
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức phù hợp với người mới
- 35/100