Skip to content

Return object information together with validation errors when many=True #9694

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

Closed
apetryla opened this issue May 5, 2025 · 2 comments
Closed

Comments

@apetryla
Copy link

apetryla commented May 5, 2025

I have this use case, when I'm using a DRF serializer with many=True (hundreds of objects). If validation fails on any of these objects, I don't know on which it fails and all I'm getting in the end is field name with too general error message to trace down the failing object.

Was diving into the source code, but it seems that there are various places in which validation error could be raised, various validation error types (including django ones) and also there could be various different validators. So I can't find a single (or two) places where I could reasonably interscept execution and insert the object information, which I need.

Any suggestions on how I could get object info along with error message in the response?

In case this is useful for others and requires reasonable effort, I'd consider contributing it upstream.

@ulgens
Copy link
Contributor

ulgens commented May 6, 2025

Any suggestions on how I could get object info along with error message in the response?

Afaik, the resulting list of errors is sth like

[],
[],
[{"field_name": ["error1", "error2"]}],
[],

which empty lists stand for the objects without validatation issues and ordering of the outputs maps to order of inputs.

@apetryla
Copy link
Author

apetryla commented May 9, 2025

Looks like this works. Sorry for this oversight from my side. Thank You for help and explanation!

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

No branches or pull requests

3 participants