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

Bad type annotation on GroupConcat expression: Expression #1054

Open
anentropic opened this issue Nov 24, 2023 · 1 comment
Open

Bad type annotation on GroupConcat expression: Expression #1054

anentropic opened this issue Nov 24, 2023 · 1 comment

Comments

@anentropic
Copy link

Python Version

3.11

Django Version

4.2

MariaDB/MySQL Version

MySQL 8.0

Package Version

latest

Description

First arg to constructor is currently annotated as expression: Expression:

https://github.com/adamchainz/django-mysql/blob/main/src/django_mysql/models/aggregates.py#L27-L37

Example usage code in docs is:

author = Author.objects.annotate(book_ids=GroupConcat("books__id")).get(
    name="William Shakespeare"
)

"books__id" is a str and not an Expression, giving type errors when using as intended

also F("books_id") would not pass either, as F does not inherit from Expression (they are both instances of Combinable)

https://github.com/django/django/blob/4.2/django/db/models/expressions.py#L474

@adamchainz
Copy link
Owner

Correct. It looks like the annotation should probably be just Any, as per the superclass: https://github.com/typeddjango/django-stubs/blob/2cb9c832e97ea5a73d11596696effaab065dff94/django-stubs/db/models/aggregates.pyi#L11 . Do you agree? If so, could you open a PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants