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

Allow to override child.run_validation call in ListSerializer #8035

Merged
merged 3 commits into from Jul 26, 2023

Conversation

pchiquet
Copy link
Contributor

@pchiquet pchiquet commented Jun 15, 2021

Description

Move child.run_validation() call to a separated method: ListSerializer.run_child_validation.

This allows to easily customize this behavior without overriding ListSerializer.to_internal_value (which duplicates rest_framework code).

It is useful to support multiple updates where child.instance should be set during run_validation (else a queryset or a list of instances is passed to child serializer).

See

@stale
Copy link

stale bot commented Apr 18, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Apr 18, 2022
@stale stale bot removed the stale label Apr 19, 2022
@pchiquet pchiquet force-pushed the list-serializer-validation branch from 8649055 to 2026e19 Compare May 10, 2022 08:25
@stale
Copy link

stale bot commented Jul 10, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Jul 10, 2022
Copy link

@felipediel felipediel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like these changes. They could enable third party apps to create writable nested list serializers concisely.

There was a PR to add that functionality to the core, but it was decided that extensions should take care of it. I think it's reasonable to decouple this method to help extend this class.

@stale stale bot removed the stale label Dec 11, 2022
Copy link
Member

@auvipy auvipy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK I guess this can be accepted to let 3rd party ext to add custom functionality. but would be great if we can add some tests

@pchiquet
Copy link
Contributor Author

OK I guess this can be accepted to let 3rd party ext to add custom functionality. but would be great if we can add some tests

I have just added a simple test with a ListSerializer that overrides run_child_validation.

  • without this custom implementation, self.instance and self.initial_data are lists during child serializer validation.
  • run_child_validation allows to set self.instance to current instance and self.initial_data to current update data.

@stale
Copy link

stale bot commented Apr 2, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Apr 2, 2023
@auvipy auvipy requested review from a team and removed request for kevin-brown April 3, 2023 07:52
@stale stale bot removed stale labels Apr 3, 2023
@stale
Copy link

stale bot commented Jun 10, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Jun 10, 2023
Copy link
Member

@auvipy auvipy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am considering accepting this on the ground of letting the 3rd party extensions to override it. do we need additional documentation?

@auvipy auvipy added this to the 3.15 milestone Jun 10, 2023
@auvipy
Copy link
Member

auvipy commented Jul 11, 2023

@pchiquet should we consider some documentation update for this?

@auvipy auvipy merged commit 589b5dc into encode:master Jul 26, 2023
math-a3k pushed a commit to math-a3k/django-rest-framework that referenced this pull request Jul 31, 2023
…#8035)

* Separated run_child_validation method in ListSerializer

* fix typo

* Add test_update_allow_custom_child_validation

---------

Co-authored-by: Pierre Chiquet <pierre.chiquet@ubikey.fr>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants