You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jun 6, 2024. It is now read-only.
I moticed that the error is incorrectly formatted when one raises a ValidationError from a pre/post decorator.
For example I have this in my Schema:
@post_loaddefmerge_dates(self, data):
# Do manipulation# ...# Additional validation on reconstructed fieldsifstart>end:
raiseValidationError("Start date and time must precede end date and time")
When an error occurs during usual validation, the errors is a dictionary with details:
But when I input some data that hits the custom validation, then the error is a string:
>>>data= {"data": {"type": "timeslot", "attributes": {"start_date": "10/08/2019","start_time": "20:00","end_date": "10/08/2019","end_time": "19:30"}}}
>>>sc.load(data)
UnmarshalResult(
data={'start_time': datetime.time(20, 0), 'end_date': datetime.date(2019, 10, 8), 'start_date': datetime.date(2019, 10, 8), 'end_time': datetime.time(19, 30)},
errors={'errors': ['Start date and time must precede end date and time']}
)
That behavior make it fail when used behind flask-rest-jsonapi.
For the moment, the workaround I found, by deep analysis of the code, is to raise a dictionary instead using the failing attribute as key and a list of string as value, so that the for loop doesn't explode the error string.
raiseValidationError({'start': ["Start date and time must precede end date and time"]})
If that's the way to go, I did not find this trick in the documentation.
The text was updated successfully, but these errors were encountered:
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
I moticed that the error is incorrectly formatted when one raises a ValidationError from a pre/post decorator.
For example I have this in my Schema:
When an error occurs during usual validation, the errors is a dictionary with details:
But when I input some data that hits the custom validation, then the error is a string:
That behavior make it fail when used behind flask-rest-jsonapi.
For the moment, the workaround I found, by deep analysis of the code, is to raise a dictionary instead using the failing attribute as key and a list of string as value, so that the for loop doesn't explode the error string.
If that's the way to go, I did not find this trick in the documentation.
The text was updated successfully, but these errors were encountered: