Opened 7 months ago

Last modified 7 months ago

#36299 closed Bug

ORM Regressions in Django 5.2 — at Initial Version

Reported by: OutOfFocus4 Owned by:
Component: Database layer (models, ORM) Version: 5.2
Severity: Release blocker Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

ORM calls that worked prior to Django 5.2 now return different results or outright fail in Django 5.2. I have attached a file with proof-of-concept tests.

The first issue I noticed is that calling alias on after values_list adds the aliased value to the result set. I believe the root of this error is in django/db/models/sql/query.py lines 1224 and 1225:

        if self.selected:
            self.selected[alias] = alias

This code adds the alias to selected regardless of the value of the select parameter.

Another issue I found causes queryset evaluation to raise an AttributeError. The following code:

with atomic():
    values = (
        User.objects.select_for_update(of=("self",))
        .values_list(
            Concat(F("first_name"), Value(" "), F("last_name")), "email"
        )
        .get(pk=12)
    )

will fail with a stacktrace ending in AttributeError: 'Concat' object has no attribute 'target'

Change History (1)

by OutOfFocus4, 7 months ago

Attachment: tests.py added
Note: See TracTickets for help on using tickets.
Back to Top