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

Validate user header #167

Merged
merged 5 commits into from
Dec 18, 2024
Merged

Validate user header #167

merged 5 commits into from
Dec 18, 2024

Conversation

dalonsoa
Copy link
Collaborator

Replaces the validate_read and validate_write with validate_header and header_to_dict, respectively.

  • validate_header is used in just after reading) and just before writing operations to ensure that the header always complies with any registered validator.
  • header_to_dict is run just before a write operation after validate_header to ensure that the header is serializable.

A couple of extra checks have been added to ensure the robustness of the process.

@dalonsoa dalonsoa requested a review from alexdewar December 18, 2024 13:38
Copy link
Contributor

@alexdewar alexdewar left a comment

Choose a reason for hiding this comment

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

LGTM! I've left a couple of small comments, but nothing important.

if key in VALIDATORS_REGISTRY:
if not isinstance(value_, dict):
Copy link
Contributor

Choose a reason for hiding this comment

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

Thinking about this, I suppose any Mapping type would work, not just dicts. The same is true for the input argument.

That said, users probably aren't going to be using other types of Mapping here all that often.

Copy link
Contributor

Choose a reason for hiding this comment

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

And would TypeError maybe be more appropriate than ValueError?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes to the second - I'll update. About the first, anything that can be unpacked with ** would work. I was not sure if Mappings in general allow this, so I sticked to dict that I know will work and, as you say, it is what most people will use.

Copy link
Collaborator Author

@dalonsoa dalonsoa Dec 18, 2024

Choose a reason for hiding this comment

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

Changed in 08e187c

@dalonsoa dalonsoa merged commit 3881fc3 into main Dec 18, 2024
7 checks passed
@dalonsoa dalonsoa deleted the validate_user_header branch December 18, 2024 14:43
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.

2 participants