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

Treat QuerySet.alias like QuerySet.annotate #2411

Merged
merged 1 commit into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions mypy_django_plugin/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ def manager_and_queryset_method_hooks(self) -> Dict[str, Callable[[MethodContext
"values_list": partial(
querysets.extract_proper_type_queryset_values_list, django_context=self.django_context
),
"alias": partial(querysets.extract_proper_type_queryset_annotate, django_context=self.django_context),
"annotate": partial(querysets.extract_proper_type_queryset_annotate, django_context=self.django_context),
"create": partial(init_create.redefine_and_typecheck_model_create, django_context=self.django_context),
"filter": typecheck_filtering_method,
Expand Down
9 changes: 5 additions & 4 deletions tests/typecheck/managers/querysets/test_annotate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@
qs.filter(annotate_wrong__gt=5)

qs2 = qs.alias(alias_entries=models.Count("entry"))
qs2.filter(alias_entries__gt=5)
qs2.filter(alias_wrong__gt=5, annotate_wrong__gt=5)

Blog.objects.annotate().filter(xyz=1)
Expand All @@ -378,10 +379,10 @@
)
out: |
main:6: error: Cannot resolve keyword 'annotate_wrong' into field. Choices are: entry, id, xyz [misc]
main:9: error: Cannot resolve keyword 'alias_wrong' into field. Choices are: entry, id, xyz [misc]
main:9: error: Cannot resolve keyword 'annotate_wrong' into field. Choices are: entry, id, xyz [misc]
main:11: error: Cannot resolve keyword 'xyz' into field. Choices are: entry, id [misc]
main:13: error: Cannot resolve keyword 'xyz' into field. Choices are: entry, id [misc]
main:10: error: Cannot resolve keyword 'alias_wrong' into field. Choices are: entry, id, xyz, alias_entries [misc]
main:10: error: Cannot resolve keyword 'annotate_wrong' into field. Choices are: entry, id, xyz, alias_entries [misc]
main:12: error: Cannot resolve keyword 'xyz' into field. Choices are: entry, id [misc]
main:14: error: Cannot resolve keyword 'xyz' into field. Choices are: entry, id [misc]
installed_apps:
- myapp
files:
Expand Down
Loading