django-mysql icon indicating copy to clipboard operation
django-mysql copied to clipboard

Bad type annotation on GroupConcat `expression: Expression`

Open anentropic opened this issue 1 year ago • 1 comments

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

anentropic avatar Nov 24 '23 12:11 anentropic