Skip to content

Conversation

charettes
Copy link
Member

Trac ticket number

Not meant to be merged, just a demonstration of how the update returning logic proposed in #19285 is future proof.

@github-actions github-actions bot added the no ticket Based on PR title, no linked Trac ticket label Mar 22, 2025
@charettes charettes force-pushed the update-returning-poc branch from f40fa0d to 3762de9 Compare March 22, 2025 16:45
@charettes charettes changed the title Demonstration of how update and bulk_update could take advantage of returning rows. Fixed #32406 -- Demonstration of how update and bulk_update could take advantage of returning rows. Mar 22, 2025
@github-actions github-actions bot removed the no ticket Based on PR title, no linked Trac ticket label Mar 22, 2025
Copy link
Member Author

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

  1. Return the dependent generated fields
  2. Clear the cached values of fields meant to be returned (generated, expressions) when not can_return_rows_from_update

@charettes charettes force-pushed the update-returning-poc branch 2 times, most recently from 56a9d95 to c323367 Compare March 23, 2025 21:57
Copy link
Member Author

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].

@charettes charettes force-pushed the update-returning-poc branch 2 times, most recently from 50c03c4 to 1aeb4d0 Compare March 24, 2025 01:31
Comment on lines 1308 to 1314
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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."
)

Comment on lines 1239 to 1313
Copy link
Member Author

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.

@charettes charettes force-pushed the update-returning-poc branch from 1aeb4d0 to cbbb5c9 Compare March 24, 2025 04:16
@charettes charettes force-pushed the update-returning-poc branch from cbbb5c9 to 3e74c53 Compare April 24, 2025 22:18
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.
@charettes charettes force-pushed the update-returning-poc branch from 3e74c53 to c6995ea Compare June 14, 2025 05:38
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

Successfully merging this pull request may close these issues.

1 participant