Skip to content

Commit

Permalink
Call model_construct in both v1 and v2 pydantic
Browse files Browse the repository at this point in the history
  • Loading branch information
timj committed Jul 19, 2023
1 parent b0faaf8 commit c1079d5
Showing 1 changed file with 8 additions and 15 deletions.
23 changes: 8 additions & 15 deletions python/lsst/pipe/base/graph/quantumNode.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
Quantum,
SerializedQuantum,
)
from lsst.daf.butler._compat import PYDANTIC_V2, _BaseModelCompat
from lsst.daf.butler._compat import _BaseModelCompat
from lsst.utils.introspection import find_outside_stacklevel

from ..pipeline import TaskDef
Expand Down Expand Up @@ -164,18 +164,11 @@ class SerializedQuantumNode(_BaseModelCompat):

@classmethod
def direct(cls, *, quantum: dict[str, Any], taskLabel: str, nodeId: str) -> SerializedQuantumNode:
if PYDANTIC_V2:
node = cls.model_construct(
__fields_set=_fields_set,
quantum=SerializedQuantum.direct(**quantum),
taskLabel=taskLabel,
nodeId=uuid.UUID(nodeId),
)
else:
node = SerializedQuantumNode.__new__(cls)
setter = object.__setattr__
setter(node, "quantum", SerializedQuantum.direct(**quantum))
setter(node, "taskLabel", taskLabel)
setter(node, "nodeId", uuid.UUID(nodeId))
setter(node, "__fields_set__", _fields_set)
node = cls.model_construct(
__fields_set=_fields_set,
quantum=SerializedQuantum.direct(**quantum),
taskLabel=taskLabel,
nodeId=uuid.UUID(nodeId),
)

return node

0 comments on commit c1079d5

Please sign in to comment.