-
Notifications
You must be signed in to change notification settings - Fork 15
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
Validation Errors when InjectionMaterials is combination of models #842
Comments
You are forcing the model to be built without validation by calling the The trace you get is not from the final from aind_data_schema.core.procedures import TarsVirusIdentifiers, NanojectInjection, ViralMaterial, NonViralMaterial
from aind_data_schema.models.organizations import Organization
ids = TarsVirusIdentifiers(virus_tars_id="AiV123", prep_lot_number="lot123")
viral = ViralMaterial(name="example", tars_identifiers=ids, titer=7000000)
non_viral = NonViralMaterial(name="example", source=Organization.ABCAM, rrid=None, lot_number="foo", expiration_date=None)
inj = NanojectInjection(injection_materials=[viral, non_viral],
injection_coordinate_ml=0, injection_coordinate_ap=0, injection_coordinate_depth=[0, +10, -10],
protocol_id="bar", injection_angle=0, injection_volume=[-10, 0, 0])
inj.model_validate(inj.model_dump()) |
This signature is incorrect and may fix the bug if we fix it: injection_materials: Annotated[
List[Union[ViralMaterial, NonViralMaterial]],
Field(title="Injection material", min_length=1, discriminator="material_type"),
] |
I think this bug might have already been fixed? I can't reproduce the bug when using Bruno's example and injection_materials already has the signature Jon suggested. Let me know if I'm missing something! |
Closing this issue because it works with Bruno's example. Opening issue in metadata-service to fix construction of models to not use model_construct |
Describe the bug
When injection_materials contains both ViralMaterial and NonViralMaterial objects, the injection fails validation due to "extra input" and "field required" errors. It is incorrectly validating ViralMaterial objects against NonViralMaterials and vice versa.
To Reproduce
Expected behavior
injection_materials is a union of ViralMaterial and NonViralMaterial. It should allow and validate correctly.
Desktop (please complete the following information):
Smartphone (please complete the following information):
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: