-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
save() may break database consistency (concurrency issue) #564
Comments
Wow, this is pretty bad... It leads to a malformed doc stored in the database:
I agree this should rather fail with an error equivalent to
|
I'm currently using a workaround of calling save() with save_condition = {}. This causes the upsert to be False. Note that setting the pk of a new object must be done during init. otherwise the document is marked as existing and the save will fail. |
I just hit this nasty bug put my db in a bad state |
save()
only saves changed fields in existing documents, This is pretty fine, but it saves withupsert=True
! So, if someone deleted the document in the meanwhile, we end-up with a document with only updated fields (and missing required fields). (We encountered to these mal-structured rows in our database.)save()
should not useupsert=True
when updating only changed fields. It may check for results and raise an exception if no document is updated (sqlalchemy has aStaleDataError
for this porpose)The text was updated successfully, but these errors were encountered: