-
-
Notifications
You must be signed in to change notification settings - Fork 401
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
fix: update pk field only raises unfriendly error #1873
base: develop
Are you sure you want to change the base?
Conversation
CodSpeed Performance ReportMerging #1873 will not alter performanceComparing Summary
|
Pull Request Test Coverage Report for Build 13179624319Details
💛 - Coveralls |
@waketzheng I added benchmarks for updates, let's merge them first so we have a baseline for performance and can be sure that this changes doesn't impact it significantly. |
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.
Can you please rebase on top of the latest changes in develop?
@@ -267,13 +267,15 @@ async def execute_update( | |||
values = [] | |||
expressions = {} | |||
for field in update_fields or self.model._meta.fields_db_projection.keys(): |
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.
The current logic assumes that if no values and no expressions, then the user must have been passed pk as part of update_fields
. That is a bit hard to follow. What do you think about the version below?
for field in update_fields or self.model._meta.fields_db_projection.keys():
field_obj = self.model._meta.fields_map[field]
if field_obj.pk:
if update_fields:
raise OperationalError(
f"Can't update pk field, use `{self.model.__name__}.create` instead."
)
continue
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.
I think we should allow .update_fields=['id', 'xxx']
as the Django do. And show warning to make sure user want to do that.
Description
Close #1870
Motivation and Context
Explicit raises OptionalError when executing
await model.save(update_fields=['id'])
How Has This Been Tested?
make ci
Checklist: