-
Notifications
You must be signed in to change notification settings - Fork 0
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
Feature/pdct 1542 change bulk import tool to not allow non strings as metadata #263
base: main
Are you sure you want to change the base?
Feature/pdct 1542 change bulk import tool to not allow non strings as metadata #263
Conversation
…-not-allow-non-strings-as-metadata
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.
This is great. There is a suggestion though that we use a parser, which might work better at scale, and also allows us to define the type of Metadata.
for value in e.get("metadata", {}).values() | ||
] | ||
|
||
_validate_values_are_strings(metadata_values) |
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.
Instead of writing our own parser, we could use Pydantic's parser? e.g.
from pydantic import BaseModel, RootModel, ValidationError
from typing import Dict, Union, List
Metadata = RootModel[Dict[str, Union[str, List[str]]]]
if __name__ == "__main__":
good_json = '{"name": "John", "age": "30", "list": ["item1", "item2"]}'
bad_json = '{"name": "John", "age": 30, "list": ["item1", "item2"]}'
try:
print(Metadata.model_validate_json(good_json))
print("Successful") # reaches here
except ValidationError as e:
print(e)
print("Failed")
try:
print(Metadata.model_validate_json(bad_json))
print("Successful")
except ValidationError as e:
print(e)
print("Failed") # reaches here with a nice descriptive error
Description
Please include:
Proposed version
Please select the option below that is most relevant from the list below. This
will be used to generate the next tag version name during auto-tagging.
Visit the Semver website to understand the
difference between
MAJOR
,MINOR
, andPATCH
versions.Notes:
used -- e.g. Major > Minor > Patch
sure your selected option is marked
[x]
with no spaces in between thebrackets and the
x
Type of change
Please select the option(s) below that are most relevant:
How Has This Been Tested?
Please describe the tests that you added to verify your changes.
Reviewer Checklist