Skip to content
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

Make nested object deletion extensible #143

Merged
merged 1 commit into from
May 26, 2021

Conversation

kavdev
Copy link
Contributor

@kavdev kavdev commented May 25, 2021

It's currently possible to extend create and update functionality by just implementing those methods on the child serializer, but deletion is a bit trickier.

This proposed refactor exposes just the place in the code where deletion takes place so that more functionality can be easily added in user code if desired.

For my particular use case, I want to be able to create events and update inventory any time a nested item is deleted. With this new change, I can simply extend perform_nested_delete(pks_to_delete, *args) to include my functionality and call super() to ensure the deletion takes place as expected.

As a side effect, this enables users to adopt functionality proposed in #103 and #112 until the PRs are accepted/declined.

It's currently possible to extend create and update functionality by just implementing those methods on the child serializer, but deletion is a bit trickier.

This proposed refactor exposes just the place in the code where deletion takes place so that more functionality can be easily added in user code if desired.

For my particular use case, I want to be able to create events and update inventory any time a nested item is deleted. With this new change, I can simply extend ``perform_nested_delete(pks_to_delete, **kwargs)`` to include my functionality and call super() to ensure the deletion takes place as expected.

As a side effect, this enables users to adopt functionality proposed in beda-software#103 and beda-software#112 until the PRs are accepted/declined.
@codecov-commenter
Copy link

codecov-commenter commented May 25, 2021

Codecov Report

Merging #143 (441ab8c) into master (f7d470f) will increase coverage by 0.01%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #143      +/-   ##
==========================================
+ Coverage   98.16%   98.18%   +0.01%     
==========================================
  Files           3        3              
  Lines         218      220       +2     
==========================================
+ Hits          214      216       +2     
  Misses          4        4              
Impacted Files Coverage Δ
drf_writable_nested/mixins.py 98.07% <100.00%> (+0.01%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f7d470f...441ab8c. Read the comment docs.

@kavdev
Copy link
Contributor Author

kavdev commented May 25, 2021

@ruscoder I'm hoping this can get merged quickly, as it's a small refactor that provides a lot of value. Let me know if there are any changes you might want me to make and I'll get on them right away.

@ruscoder
Copy link
Member

Hi @kavdev! Thanks for the contribution. Seems a good general solution for now.

@ruscoder ruscoder merged commit 307f21a into beda-software:master May 26, 2021
@ruscoder
Copy link
Member

I'm not sure that perform_nested_delete is good for public usage due to a lot of arguments, but maybe it can be good for extensibility. Merged

@ruscoder
Copy link
Member

Available in 0.6.3

@kavdev kavdev deleted the patch-1 branch May 26, 2021 19:17
@kavdev
Copy link
Contributor Author

kavdev commented May 26, 2021

@ruscoder fantastic, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants