-
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
fix tests after model update with version and model version, and extend forbidding extra fields to nested nodes #135
Conversation
…nd forbidding extra fields to nested nodes
@@ -155,5 +155,5 @@ def persist(object_list: List, object_path: str, sumbission_accno: str): | |||
|
|||
def filter_model_dictionary(dictionary: dict, target_model: Type[BaseModel]): | |||
accepted_fields = target_model.model_fields.keys() | |||
result_dict = {key: dictionary[key] for key in accepted_fields} | |||
result_dict = {key: dictionary[key] for key in accepted_fields if key in dictionary} |
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.
Fix to cope with optional/missing fields in the original dictionary
|
||
class ConfiguredBaseModel(BaseModel): | ||
# Throw error if you try to validate/create model from a dictionary with keys that aren't a field in the model | ||
model_config = ConfigDict(extra="forbid") |
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.
Moved to the semantic models to make sure there isn't an edge case where e.g. a study can't have extra fields, but a contributor in a study can
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.
btw nice find, we've literally had this bug in the api for nested objects since forever
@@ -41,6 +38,7 @@ def __init__(self, *args, **data): | |||
) | |||
model_metadata_existing = data.get("model", None) | |||
if model_metadata_existing: | |||
model_metadata_existing = ModelMetadata(**model_metadata_existing) |
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.
Fix to the error checking - as it was currently trying to compare a dictionary with a model. This was in the original API models but was missed when copied over to here.
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.
LGTM
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.
LGTM!
…nd forbidding extra fields to nested nodes (#135) * fix tests after model update with version and model version, and extend forbidding extra fields to nested nodes * Update experimental_imaging_dataset.py * Update utils.py
…nd forbidding extra fields to nested nodes (#135) * fix tests after model update with version and model version, and extend forbidding extra fields to nested nodes * Update experimental_imaging_dataset.py * Update utils.py
Fixes tests broken by: #128 (review)
Also moves the configuration that forbids extra fields into the semantic models file to be inherited instead of BaseModel. This stops extra fields from being passed into models that govern 'nested'/'embedded' json objects inside other json objects
Also updates the filter model dictionary function to work with/expect optional fields.