django-rest-framework icon indicating copy to clipboard operation
django-rest-framework copied to clipboard

Allow to override child.run_validation call in ListSerializer

Open pchiquet opened this issue 3 years ago • 2 comments

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

  • https://github.com/encode/django-rest-framework/discussions/7805 / https://github.com/encode/django-rest-framework/issues/6130
  • https://github.com/encode/django-rest-framework/issues/5345

pchiquet avatar Jun 15 '21 09:06 pchiquet

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[bot] avatar Apr 18 '22 08:04 stale[bot]

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[bot] avatar Jul 10 '22 05:07 stale[bot]

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.

pchiquet avatar Dec 13 '22 16:12 pchiquet

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[bot] avatar Apr 02 '23 20:04 stale[bot]

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[bot] avatar Jun 10 '23 04:06 stale[bot]

@pchiquet should we consider some documentation update for this?

auvipy avatar Jul 11 '23 14:07 auvipy