Add more unit tests, use DataclassValidatorFieldException#5
Merged
Conversation
JGaukrogers
reviewed
Mar 31, 2026
flauschzelle
reviewed
Apr 2, 2026
ninanomenon
reviewed
Apr 7, 2026
Comment on lines
+102
to
+109
| assert type(fields['regular_required'].metadata.get('validator')) is StringValidator | ||
| assert type(fields['regular_optional'].metadata.get('validator')) is StringValidator | ||
| assert type(fields['explicit_field'].metadata.get('validator')) is StringValidator | ||
| assert type(fields['filter1'].metadata.get('validator')) is IntegerValidator | ||
| assert type(fields['filter2'].metadata.get('validator')) is IntegerValidator | ||
| assert type(fields['filter3'].metadata.get('validator')) is IntegerValidator | ||
| assert type(fields['filter4'].metadata.get('validator')) is MultiSelectIntegerValidator | ||
| assert type(fields['filter5'].metadata.get('validator')) is BooleanValidator |
There was a problem hiding this comment.
I wonder if isinstance is more correct here
Contributor
Author
There was a problem hiding this comment.
In general it's better to use isinstance() because it works with subtypes as well, yes. It's less strict.
But here in the unit tests, I don't really see a reason to use a less strict test. The validators should always have the exact types that we used in the dataclass definition. Otherwise something is happening that somehow modifies the validators, which would be unexpected behavior.
ninanomenon
approved these changes
Apr 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds some more unit tests to the project. I figured it makes sense to have some more unit tests before updating to validataclass 0.12 and changing several things related to that.
I also noticed an inconsistency between the
@search_query_dataclassand@validataclassdecorators, where the former didn't use theDataclassValidatorFieldExceptionclass for errors that are similar or the same as those in the@validataclassdecorator, so I fixed that. I don't consider this a breaking change, because it's just a different exception class for errors that effectively mean your code isn't valid.