Skip to content

Commit 98897f7

Browse files
committed
Add synthesis_products field with self-loop by default
1 parent 22a5b89 commit 98897f7

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

pydatalab/schemas/sample.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,14 @@
130130
"$ref": "#/definitions/Constituent"
131131
}
132132
},
133+
"synthesis_products": {
134+
"title": "Synthesis Products",
135+
"default": [],
136+
"type": "array",
137+
"items": {
138+
"$ref": "#/definitions/Constituent"
139+
}
140+
},
133141
"synthesis_description": {
134142
"title": "Synthesis Description",
135143
"type": "string"

pydatalab/src/pydatalab/models/samples.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,23 @@ class Sample(Item):
1717
synthesis_constituents: List[Constituent] = Field([])
1818
"""A list of references to constituent materials giving the amount and relevant inlined details of consituent items."""
1919

20+
synthesis_products: List[Constituent] = Field([])
21+
"""A list of references to constituent materials giving the amount and relevant inlined details of relevant sythesis products."""
22+
2023
synthesis_description: Optional[str]
2124
"""Free-text details of the procedure applied to synthesise the sample"""
2225

26+
@root_validator
27+
def add_self_product(cls, values):
28+
if not values.get("synthesis_products"):
29+
values["synthesis_products"].append(
30+
Constituent(
31+
quantity=None, item={"type": values["type"], "item_id": values["item_id"]}
32+
)
33+
)
34+
35+
return values
36+
2337
@root_validator
2438
def add_missing_synthesis_relationships(cls, values):
2539
"""Add any missing sample synthesis constituents to parent relationships"""

pydatalab/src/pydatalab/routes/v0_1/items.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -882,7 +882,7 @@ def get_item_data(
882882
)
883883

884884
# Must be exported to JSON first to apply the custom pydantic JSON encoders
885-
return_dict = json.loads(doc.json(exclude_unset=True))
885+
return_dict = json.loads(doc.json())
886886

887887
if item_id is None:
888888
item_id = return_dict["item_id"]

0 commit comments

Comments
 (0)