Repository navigation
ListSerializer.errors raises AttributeError when the single error is a dict #10109
Unanswered
b84330808
asked this question in
Potential Issue
Replies: 1 comment
|
This looks like it was already fixed in 3.5.1. Both checks on
if isinstance(ret, list) and len(ret) == 1 and getattr(ret[0], 'code', None) == 'null':That line came from f1bdce1 (#4609, October 2016) for #4606. The same example is still in the suite as Your snippet, with a bare So 3.5.0 is the last release that raises the |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Posting here first as suggested before opening a PR.
When a
ListSerializer(many=True) validates a single item and that item has field errors,.errorsreturns a list containing one dict. The edge-case check inSerializer.errorsandListSerializer.errorsdoesret[0].code == 'null', which raisesAttributeError: 'dict' object has no attribute 'code'instead of returning the errors.Minimal reproduction:
The fix I have prepared changes both occurrences to
getattr(ret[0], 'code', None) == 'null', so the 'No data provided' special case still applies only when the single error really is the null ErrorDetail, and dict-shaped errors pass through. A regression test is included.Happy to open the PR if this approach looks right.
All reactions