Skip to content

Conversation

@Shrikantgiri25
Copy link
Contributor

When a nested serializer raises a parent-level ValidationError, the resulting
error value is a list rather than a mapping. Accessing child bound fields in this
case causes NestedBoundField.__getitem__() to pass None for errors, breaking
the bound-field contract.

This change normalizes list-based errors to an empty dict when resolving child
bound fields, ensuring they remain accessible.

Adds a regression test for issue #4073.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a bug where accessing child bound fields fails after a parent-level validation error in nested serializers. When a nested serializer raises a parent-level ValidationError (resulting in a list rather than a dict), the NestedBoundField.__getitem__() method was passing None for errors, breaking the bound-field contract.

Key changes:

  • Normalizes list-based errors to an empty dict when resolving child bound fields
  • Adds regression test for issue #4073

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
rest_framework/utils/serializer_helpers.py Updated NestedBoundField.__getitem__() to handle list-based errors by normalizing them to an empty dict
tests/test_bound_fields.py Added regression test verifying child bound fields remain accessible after parent-level validation errors

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

1 participant