Fix silent deserialization failure with unique together constraint#313
Conversation
| :returns: True if save succeeded, False otherwise | ||
| """ | ||
| try: | ||
| with transaction.atomic(): |
There was a problem hiding this comment.
This is so that the outer transaction stays healthy, and we can keep saving other records.
bjester
left a comment
There was a problem hiding this comment.
This is really mostly complete, just some cleanup and tidying code.
And the small deserialization_exception enhancement!
| exceptions.ValidationError, | ||
| exceptions.ObjectDoesNotExist, | ||
| ValueError, | ||
| ) as e: |
There was a problem hiding this comment.
Perhaps we don't need this try/except anymore? So we can simplify this, leveraging the behavior of _save_deserialized_record
There was a problem hiding this comment.
I initially tried removing the try/except around _deserialize_store_model to reduce code, but I think keeping it is actually better. The reason is that there are two different things that can go wrong at two different moments. the json from the Store might fail having a deserialization failure. Second, our unique constraint violation case. clarity is worth the few extra lines?
| continue | ||
| _save_deserialized_record( | ||
| store_model, app_model, model.__name__, excluded_list | ||
| ) |
There was a problem hiding this comment.
The excluded_list doesn't seem necessary here, so maybe it's made optional for this function?
There was a problem hiding this comment.
We do execute excluded_list.append(store_model.id) to keep track of shared failed ids?
There was a problem hiding this comment.
Yes but the purpose for that list is this very loop. So modifying the list is a bit redundant, and theoretically makes the in check slower every iteration without any benefit.
The store_model.id is unique and the same as app_model.id, so as this loops through the store+app models, if the ID gets added to the excluded_list, it will never come up again in the loop.
morango/sync/operations.py
Outdated
|
|
||
| :returns: True if save succeeded, False otherwise | ||
| """ | ||
| from django.db import transaction as django_transaction |
There was a problem hiding this comment.
Strange, I did see the issue the CI. We already have transaction imported. Once the other stuff is tackled, it might be worth dropping the commit to see if it fails again.
Summary
TODO
Reviewer guidance
Issues addressed
closes #306