Skip to content

Commit

Permalink
Use model_construct in pydantic v2
Browse files Browse the repository at this point in the history
They changed the name of __fields_set__.
  • Loading branch information
timj committed Jul 18, 2023
1 parent 5f59d1d commit a3aaef7
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 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 _BaseModelCompat
from lsst.daf.butler._compat import PYDANTIC_V2, _BaseModelCompat
from lsst.utils.introspection import find_outside_stacklevel

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

@classmethod
def direct(cls, *, quantum: dict[str, Any], taskLabel: str, nodeId: str) -> SerializedQuantumNode:
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)
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)

Check warning on line 180 in python/lsst/pipe/base/graph/quantumNode.py

View check run for this annotation

Codecov / codecov/patch

python/lsst/pipe/base/graph/quantumNode.py#L175-L180

Added lines #L175 - L180 were not covered by tests
return node

0 comments on commit a3aaef7

Please sign in to comment.