import_importlib leaks module attr sets
Ninguém assumiu esta issue ainda.
- Linguagem predominante
- Python
- Estrelas
- 77.2k
- Forks
- 36k
- Métricas de merge de PRs
- Métricas de PR pendentes
Descrição
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
Guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Direção de pesquisa
Comece com test_importlib.util.import_importlib() e, em seguida, reproduza a falha em test_pickle e test_pickletool. Rastreie como a importação temporária de importlib altera builtins.loader e builtins.spec; o trabalho estará concluído quando os valores originais forem restaurados e ambos os testes passarem sem o PicklingError. Um PR vinculado, gh-154276, indica que o trabalho já está em andamento.
Escrita pelo modelo de indexação a partir do texto da issue.
Avaliação
- Stack de tecnologia
- python
- Domínio
- backend, testing-qa
- Tipo de issue
- Bug
- Dificuldade
- 3/5
- Tempo estimado
- 1-2 dias
- Status de atividade
- Estagnada
- Clareza
- Claramente especificada
- Facilidade para iniciantes
- 35/100