Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AssertionError: Cannot find component <model>_ManyRelatedManager for <app>.models.<model>_ManyRelatedManager #1861

Open
intgr opened this issue Dec 7, 2023 · 5 comments
Labels
bug Something isn't working regression Behavior has changed for worse with a release

Comments

@intgr
Copy link
Collaborator

intgr commented Dec 7, 2023

Bug report

What's wrong

After upgrading to django-stubs 4.2.7, one of my projects has developed an issue when used with mypy incremental mode.

It occurs when scanning some specific source file that has type errors. Running mypy the first with a clean cache successfully reports the type error. Running the second time, it fails with AssertionError. I haven't yet isolated a reproducible test case.

mypy --no-incremental is a work-around for this issue. Also reverting #1805 fixes it.

Traceback (most recent call last):
  File ".../bin/mypy", line 8, in <module>
    sys.exit(console_entry())
             ^^^^^^^^^^^^^^^
  File ".../site-packages/mypy/__main__.py", line 15, in console_entry
    main()
  File "mypy/main.py", line 99, in main
  File "mypy/main.py", line 178, in run_build
  File "mypy/build.py", line 189, in build
  File "mypy/build.py", line 263, in _build
  File "mypy/build.py", line 2941, in dispatch
  File "mypy/build.py", line 3332, in process_graph
  File "mypy/build.py", line 3413, in process_fresh_modules
  File "mypy/build.py", line 2109, in fix_cross_refs
  File "mypy/fixup.py", line 52, in fixup_module
  File "mypy/fixup.py", line 156, in visit_symbol_table
  File "mypy/fixup.py", line 72, in visit_type_info
  File "mypy/fixup.py", line 158, in visit_symbol_table
  File "mypy/nodes.py", line 1035, in accept
  File "mypy/fixup.py", line 211, in visit_var
  File "mypy/types.py", line 1429, in accept
  File "mypy/fixup.py", line 230, in visit_instance
  File "mypy/fixup.py", line 365, in lookup_fully_qualified_typeinfo
  File "mypy/lookup.py", line 49, in lookup_fully_qualified
AssertionError: Cannot find component `<model>_ManyRelatedManager` for `<app>.models.<model>_ManyRelatedManager`

How is that should be

No error. :)

System information

  • python version: 3.11.6
  • django version: 4.2.8
  • mypy version: 1.7.0
  • django-stubs version: 4.2.7
  • django-stubs-ext version: 4.2.7
@intgr intgr added bug Something isn't working regression Behavior has changed for worse with a release labels Dec 7, 2023
@flaeppe
Copy link
Member

flaeppe commented Dec 7, 2023

I'm getting a feeling it might be hard to hunt this down without a repro that allows us to inspect the cache.

@flaeppe
Copy link
Member

flaeppe commented Dec 7, 2023

The relevant lines where the <model>_ManyRelatedManager is inserted are here:

related_manager_info = helpers.add_new_class_for_module(
module=checker.modules[related_model_instance.type.module_name],
name=f"{related_model_instance.type.name}_ManyRelatedManager",
bases=[many_related_manager, default_manager_node.type],
)

@flaeppe
Copy link
Member

flaeppe commented Dec 12, 2023

Hm, I wonder if the issue seen here could be something similar to the findings in: #1872 (comment)

@intgr
Copy link
Collaborator Author

intgr commented Dec 12, 2023

If you can't figure this out, I'll probably find time to reduce this to a reproducer by the end of the week.

@flaeppe
Copy link
Member

flaeppe commented May 28, 2024

Did you find any repro case in the end?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working regression Behavior has changed for worse with a release
Development

No branches or pull requests

2 participants