Add add_or_update to DiffSync class.#70
Add add_or_update to DiffSync class.#70dgarros merged 19 commits intonetworktocode:mainfrom FragmentedPacket:50-get-or-create
Conversation
glennmatthews
left a comment
There was a problem hiding this comment.
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_createfunctionality, 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_createfunctionality 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 <glenn.matthews@networktocode.com>
Co-authored-by: Glenn Matthews <glenn.matthews@networktocode.com>
…ctAlreadyExists, other feedback.
|
@dgarros Not sure if you want to review it before it gets merged in. |
dgarros
left a comment
There was a problem hiding this comment.
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. |
dgarros
left a comment
There was a problem hiding this comment.
Looks great, thanks @FragmentedPacket
I think it does |
|
I'll merge since Glenn already approved it |
Fixes #50
add_or_updateto DiffSync class that requires aDiffSyncModelto be passed in and will attempt to add or update an existing object