Skip to content

Conversation

@lee3jjang
Copy link
Contributor

@lee3jjang lee3jjang commented Dec 7, 2025

I have made things!

Related issues

Summary

This PR fixes the "maximum semantic analysis iteration count reached" error that was introduced in django-stubs 5.0.3.

Problem

When create_manager_info_from_from_queryset_call() returns None, the code unconditionally calls add_symbol_table_node() with a PlaceholderNode on every iteration. This sets mypy's progress = True, preventing the semantic analysis loop from terminating.

The issue was introduced in PR #2228 as a hack for python/mypy#17402, but the implementation causes infinite iterations when the from_queryset call cannot be resolved immediately.

Solution

Check if a PlaceholderNode already exists before adding a new one. This prevents redundant symbol table modifications that trigger infinite iterations while still maintaining the original hack for python/mypy#17402.

Changes

  • Added a check for existing PlaceholderNode before calling add_symbol_table_node() in create_new_manager_class_from_from_queryset_method()

@UnknownPlatypus
Copy link
Contributor

This would be nice to have a test showing the max iteration issue so that we can be sure this resolves it. See #2228 for an exemple

When `create_manager_info_from_from_queryset_call()` returns `None`,
the code unconditionally called `add_symbol_table_node()` with a
`PlaceholderNode` on every iteration. This sets mypy's `progress = True`,
preventing the semantic analysis loop from terminating, resulting in
"maximum semantic analysis iteration count reached" error.

The fix checks if a `PlaceholderNode` already exists before adding a
new one, preventing redundant symbol table modifications that trigger
infinite iterations.

Fixes typeddjango#2373
@lee3jjang lee3jjang force-pushed the fix-infinite-loop-from-queryset branch from bb9b66e to f8348e1 Compare December 7, 2025 10:16
@lee3jjang lee3jjang marked this pull request as draft December 7, 2025 10:21
@lee3jjang
Copy link
Contributor Author

lee3jjang commented Dec 7, 2025

I tried extensively to create a test that triggers the exact "maximum semantic analysis iteration count reached" error, but it was difficult because create_manager_info_from_from_queryset_call() returning None is transient - mypy resolves forward references after a few iterations.

The test test_from_queryset_repeated_deferral_with_forward_metaclass does exercise the None path (verified with debug output), but the forward metaclass resolves quickly before hitting max iterations.

Real-world validation: This fix resolved the error in my production codebase that was failing with django-stubs 5.0.3+.

@lee3jjang lee3jjang marked this pull request as ready for review December 7, 2025 11:32
Copy link
Member

@sobolevn sobolevn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks correct to me, thank you!

@UnknownPlatypus UnknownPlatypus merged commit 0b612cd into typeddjango:master Dec 7, 2025
44 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Maximum semantic analysis iteration count reached error with django-stubs 5.0.3 & 5.0.4

3 participants