-
-
Notifications
You must be signed in to change notification settings - Fork 399
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: models get_or_create keyerror #1584
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
eac9e73
add tests
jiangying000 95f2547
add changelog
jiangying000 6e1e1f9
add changelog
jiangying000 44f7b43
fix
jiangying000 d36cfc5
Merge branch 'develop' into develop
jiangying000 d6d6dfc
merge
jiangying000 57958df
throw
jiangying000 33db833
fix test
jiangying000 b2ec794
Remove unnecessary import and update method doc
waketzheng ea7b404
More test cases for update_or_create method
waketzheng 665a36c
refactor: only query once before create for update_or_create method
waketzheng 8ac9ddf
merge remote
waketzheng 173411e
Merge branch 'develop' of github.com:tortoise/tortoise-orm into fix-g…
waketzheng 038b475
Merge pull request #1 from waketzheng/fix-get-or-create-keyerror
jiangying000 260bd9d
Merge branch 'develop' of github.com:tortoise/tortoise-orm into develop
waketzheng 9562b43
Update changelog and fix mssql ci error
waketzheng feb9b9a
Merge pull request #2 from waketzheng/fix-mssql
jiangying000 a8dab73
fix codacy issues
waketzheng 8725fa4
Merge pull request #3 from waketzheng/fix-codacy-issues
jiangying000 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
kwargs
is 'Query parameters',defaults
is 'Default values used to update the object', when they have same key with different values, value ofkwargs
should be covered bydefaults
. That is to say code must be:merged_defaults = {**kwargs, **defaults}
try:
(just put it after line 1082)return ...
shoud be stay as one line, do not make it into three lines.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.
thanks, done
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.
Even though that is how it works in django - for me it seems strange that
default
value overrides explicit valueI would expect opposite behaviour of this
I dunno if we should proceed with this change, as leaving merging on user side seems like more transparent behaviour
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 would also expect explicit kv overrides the default
do merge rather than throw err seems better for me
when i write:
i was expecting row with id 135 being updated or created
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.
It seems to me - in your case you should do explicit
get_or_create
withoutdefaults
and them make usualupdate()
for returned objectThat shouldn't affect performance, as it is basically what we already do
Django also, from 5.0, introduced separate
create_defaults
param forupdate_to_create
for similar cases to make them less confusingMay be we should look into doing it too, but it seems there could be some issues in tortoise to use
select_for_update
withget_or_create
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.
Our team use tortoise-orm for a long time, and we are proficient in django. So we prefer it have the same result with django.
Or maybe an exception can be raised when kwargs and defaults have same key with different values:
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 would prefer that, as django behaviour seems confusing to me here, but doing solution opposite to them - would be also confusing
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.
ok, updated
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 diff from github is wrong