-
Notifications
You must be signed in to change notification settings - Fork 3
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
✨ [#234] Validate DigitaalAdres.adres if type is email #271
Conversation
src/openklant/components/klantinteracties/api/tests/test_digitaal_adres.py
Show resolved
Hide resolved
src/openklant/components/klantinteracties/api/serializers/digitaal_adres.py
Outdated
Show resolved
Hide resolved
4ee5686
to
90076ed
Compare
raise exceptions.ValidationError({"adres": e.message}) | ||
else: | ||
raise ValidationError({"adres": e}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately I found no way around this, ideally I'd always raise a django.core.exceptions.ValidationError
, but I wasn't able to raise that as a field specific error in rest_framework (it was always in the data as nonFieldErrors
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean it shows up as nonFieldErrors
in the admin? It might be related to calling the validator in the clean
method (as opposed to the clean_<field>
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No in the admin it works as expected, but the API returns it as a nonfielderror, regardless of whether I re-raise the error like this: raise ValidationError({"adres": e})
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmmm, what about not using a validator (at the serializer level) but using the validate
method on the specific serializer (as this validation is done for a very specific use case)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, I've changed it so now I do not have to re-raise the error anymore
d0ba61e
to
d834c2a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
d834c2a
to
48b7490
Compare
* add explicit API test to check if no validation is applied if soort != email * remove re-raising of validationerrors for email validation in case of API context * move retrieval of soort_digitaal_adres to caller code (admin/serializer.validate)
48b7490
to
5e1ee41
Compare
Fixes #234
Changes