-
Notifications
You must be signed in to change notification settings - Fork 32
Add add_or_update to DiffSync class. #70
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
Add add_or_update to DiffSync class. #70
Conversation
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 for the PR!
While this looks like an interesting feature I'm not sure it fully addresses #50. I think I'd like to see functionality for all of the following to be able to consider #50 as "done":
- Allow
add()
ing the same identical object repeatedly without it being considered an error condition. (Noupdate()
as part of this call, and in fact if the new object differs in any attrs from the previously added object, this should still raiseObjectAlreadyExists
) get_or_create
functionality, similar to Django's, that either retrieves a previously stored item (whose ids and attrs match the provided values) or instantiates andadd()
s a new item, then returns it. Probably would be useful to follow Django's example and have this function return a tuple(record, bool_created)
update_or_create
functionality to either find an existing object by ids and update with the provided attrs, or create a new object with the given ids and attrs, and in either case return the object. (Again, returning(record, bool_created)
would be a good plan)
I'm also uncertain whether it's correct/desirable to call obj.update()
as a part of any of the above APIs, versus directly just updating its attrs
without making such a call - recall that obj.update()
implies a change to be propagated/written to the underlying system or database, which should normally only happen as a result of a DiffSync.sync()
call.
…er when attempting to add duplicate.
@glennmatthews Do you mind reviewing my latest commits to make sure I'm on the right path? |
…s within __init__.py. Add tests for exception returns.
…hhat wasn't being used.
Co-authored-by: Glenn Matthews <[email protected]>
Co-authored-by: Glenn Matthews <[email protected]>
…ctAlreadyExists, other feedback.
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.
Great stuff!
@dgarros Not sure if you want to review it before it gets merged in. |
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.
LGTM, great work @FragmentedPacket and thanks helping with this one
One last change for me before merging
please. can you add a README.md in the new example directory (04-XX) and add a link to this readme file in the documentation > diffsync/docs/source/examples/index.rst
@dgarros I completely forgot to even write any docs for this so thanks for catching that. |
Does this also address #73? Just want to make sure once this is merged, we can close it. |
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.
Looks great, thanks @FragmentedPacket
I think it does |
I'll merge since Glenn already approved it |
Fixes #50
add_or_update
to DiffSync class that requires aDiffSyncModel
to be passed in and will attempt to add or update an existing object