Skip to content

Commit

Permalink
Revert use of pydantic_core.from_json() in labware def validation.
Browse files Browse the repository at this point in the history
from_json() appears not to be *exactly* a drop-in replacement for json.loads(): it raises different exceptions for invalid input. We could certainly account for that, but for better testing and reviewing, it seems like it should be in a different PR at this point.

I'm not reverting the multi-schema additions to this function because there doesn't seem to be a problem with those.
  • Loading branch information
SyntaxColoring committed Dec 12, 2024
1 parent 212e876 commit a17012f
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions api/src/opentrons/protocols/labware.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from pathlib import Path
from typing import Any, AnyStr, Dict, Optional, Union, List

from pydantic_core import from_json
import jsonschema # type: ignore

from opentrons_shared_data import load_shared_data, get_shared_data_root
Expand Down Expand Up @@ -128,7 +127,7 @@ def save_definition(


def verify_definition(
contents: Union[AnyStr, LabwareDefinition, Dict[str, Any]],
contents: Union[AnyStr, LabwareDefinition, Dict[str, Any]]
) -> LabwareDefinition:
"""Verify that an input string is a labware definition and return it.
Expand All @@ -140,14 +139,14 @@ def verify_definition(
:returns: The parsed definition
"""
schemata_by_version = {
2: from_json(load_shared_data("labware/schemas/2.json").decode("utf-8")),
3: from_json(load_shared_data("labware/schemas/3.json").decode("utf-8")),
2: json.loads(load_shared_data("labware/schemas/2.json").decode("utf-8")),
3: json.loads(load_shared_data("labware/schemas/3.json").decode("utf-8")),
}

if isinstance(contents, dict):
to_return = contents
else:
to_return = from_json(contents)
to_return = json.loads(contents)
try:
schema_version = to_return["schemaVersion"]
schema = schemata_by_version[schema_version]
Expand Down

0 comments on commit a17012f

Please sign in to comment.