Fix infinite semantic analysis loop when using from_queryset #2935
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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()returnsNone, the code unconditionally callsadd_symbol_table_node()with aPlaceholderNodeon every iteration. This sets mypy'sprogress = 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_querysetcall cannot be resolved immediately.Solution
Check if a
PlaceholderNodealready 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
PlaceholderNodebefore callingadd_symbol_table_node()increate_new_manager_class_from_from_queryset_method()