-
-
Notifications
You must be signed in to change notification settings - Fork 33.1k
Fixed #32406 -- Demonstration of how update and bulk_update could take advantage of returning rows. #19298
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
base: main
Are you sure you want to change the base?
Conversation
f40fa0d
to
3762de9
Compare
django/db/models/query.py
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we take the same approach as Model.save
to
- Return the dependent generated fields
- Clear the cached values of fields meant to be returned (generated, expressions) when
not can_return_rows_from_update
56a9d95
to
c323367
Compare
django/db/models/query.py
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Explicitly not named returning_fields
as some backends (e.g. Postgres) allows any expressions to be returned so it could eventually be adapted not only to accept returning: Iterable[str]
but also returning: Iterable[str | Resolvable]
.
50c03c4
to
1aeb4d0
Compare
django/db/models/query.py
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if not isinstance(returning, (bool, Iterable)): | |
raise TypeError( | |
f"{returning_type} must be either a boolean or an iterable." | |
) | |
if returning is True: | |
returning_fields = opts.local_concrete_fields | |
else: | |
if returning is True: | |
returning_fields = opts.local_concrete_fields | |
elif isinstance(returning, Iterable): | |
... | |
else: | |
raise TypeError( | |
f"{returning_type} must be True or an iterable." | |
) |
django/db/models/query.py
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are only added to explain the signature handling bellow better before the docs are adjusted.
1aeb4d0
to
cbbb5c9
Compare
cbbb5c9
to
3e74c53
Compare
Determining if a field is db_returning based on the default connection feature availability prevent the usage of RETURNING for db_default fields in setups where non-default backends do support RETURNING. Whether or not the field should be attempted to be returned is already checked at the compiler level which is backend aware.
…ries. Renamed existing methods and abstractions used for INSERT … RETURNING to be generic enough to be used in the context of UPDATEs as well. Also consolidated SQL compliant implementations on BaseDatabaseOperations.
…date. This required implementing UPDATE RETURNING machinery that heavily borrows from the INSERT one.
…save(). Removed the can_return_columns_from_insert skip gates on existing field_defaults tests to confirm the expected number of queries are performed and that returning field overrides are respected.
Included an @overload to better explify signature.
3e74c53
to
c6995ea
Compare
Trac ticket number
Not meant to be merged, just a demonstration of how the update returning logic proposed in #19285 is future proof.