Skip to content
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

Merged
merged 4 commits into from
Nov 8, 2024

Conversation

stevenbal
Copy link
Collaborator

Fixes #234

Changes

  • Validate DigitaalAdres.adres if type is email

@stevenbal stevenbal requested a review from SonnyBA October 18, 2024 14:04
@stevenbal stevenbal marked this pull request as draft October 24, 2024 08:28
@stevenbal stevenbal force-pushed the feature/234-email-validation branch from 4ee5686 to 90076ed Compare October 24, 2024 13:18
Comment on lines 193 to 195
raise exceptions.ValidationError({"adres": e.message})
else:
raise ValidationError({"adres": e})
Copy link
Collaborator Author

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)

Copy link
Contributor

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>)

Copy link
Collaborator Author

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})

Copy link
Contributor

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)?

Copy link
Collaborator Author

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

@stevenbal stevenbal requested a review from SonnyBA October 24, 2024 13:20
@stevenbal stevenbal marked this pull request as ready for review October 24, 2024 13:20
@stevenbal stevenbal force-pushed the feature/234-email-validation branch 2 times, most recently from d0ba61e to d834c2a Compare October 25, 2024 08:30
@stevenbal stevenbal requested a review from annashamray October 31, 2024 08:22
Copy link
Contributor

@annashamray annashamray left a comment

Choose a reason for hiding this comment

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

Looks good!

@stevenbal stevenbal force-pushed the feature/234-email-validation branch from d834c2a to 48b7490 Compare November 8, 2024 11:23
* 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)
@stevenbal stevenbal force-pushed the feature/234-email-validation branch from 48b7490 to 5e1ee41 Compare November 8, 2024 11:27
@stevenbal stevenbal removed the request for review from SonnyBA November 8, 2024 11:30
@stevenbal stevenbal dismissed SonnyBA’s stale review November 8, 2024 11:31

already reviewed and approved

@stevenbal stevenbal merged commit d883724 into master Nov 8, 2024
25 checks passed
@stevenbal stevenbal deleted the feature/234-email-validation branch November 8, 2024 11:33
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.

Validation of any stored email address
3 participants