Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#32752 closed Bug (duplicate)

Annotation yields ProgrammingError error when migrating from 2.2 to 3.x

Reported by: Maarten van Keulen Owned by: nobody
Component: Database layer (models, ORM) Version: 3.2
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


I am in the process of migrating from Django 2.2 to 3.2. After fixing most deprecation issues, an annotation I rely on throughout my project is throwing a syntax error.

This is a bit of a mystery to me since the upgrade path lists nothing on this topic. Also, it does not appear to matter which 3.x version I use, BUT this annotation has worked throughout most of 2.2.x's versions.

    Q(assignment__is_group_assignment=True) | Q(p_user__in=F('authors__user'), can_have_journal=True),

Here is a diff of the generated SQL:

This is the errror:

django.db.utils.ProgrammingError: syntax error at or near 
LINE 1: ...ave_journal" AND "VLE_participation"."user_id" IN "VLE_assig...

Part of the trace:

venv/lib/python3.8/site-packages/django/db/models/ in __getitem__
venv/lib/python3.8/site-packages/django/db/models/ in _fetch_all
    self._result_cache = list(self._iterable_class(self))
venv/lib/python3.8/site-packages/django/db/models/ in __iter__
    results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)
venv/lib/python3.8/site-packages/django/db/models/sql/ in execute_sql
    cursor.execute(sql, params)
venv/lib/python3.8/site-packages/sentry_sdk/integrations/django/ in execute
    return real_execute(self, sql, params)
venv/lib/python3.8/site-packages/django/db/backends/ in execute
    return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
venv/lib/python3.8/site-packages/django/db/backends/ in _execute_with_wrappers
    return executor(sql, params, many, context)
venv/lib/python3.8/site-packages/django/db/backends/ in _execute
    return self.cursor.execute(sql, params)
venv/lib/python3.8/site-packages/django/db/ in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value

I attempted to dress down our repo so it would be more straightforward to reproduce the issue:
The single test should pass on Django 2.2.x and fail from Django 3.x.

Change History (2)

comment:1 by Mariusz Felisiak, 3 years ago

Component: UncategorizedDatabase layer (models, ORM)
Resolution: duplicate
Status: newclosed

Duplicate of #31135. You should use p_user=F('authors__user').

in reply to:  1 comment:2 by Maarten van Keulen, 3 years ago

Replying to Mariusz Felisiak:

Duplicate of #31135. You should use p_user=F('authors__user').

Good fit, m.b. thank you reviewing the issue swiftly.

Note: See TracTickets for help on using tickets.
Back to Top