Skip to content
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

Patch skip rc #4146

Merged
merged 4 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions cg/services/orders/validation/models/order.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from pydantic import BaseModel, Field, PrivateAttr, model_validator
from pydantic import BaseModel, BeforeValidator, Field, PrivateAttr, model_validator
from typing_extensions import Annotated

from cg.constants import DataDelivery
from cg.models.orders.constants import OrderType
from cg.services.orders.validation.models.utils import set_null_to_false


class Order(BaseModel):
Expand All @@ -10,7 +12,7 @@ class Order(BaseModel):
delivery_type: DataDelivery
order_type: OrderType = Field(alias="project_type")
name: str = Field(min_length=1)
skip_reception_control: bool = False
skip_reception_control: Annotated[bool, BeforeValidator(set_null_to_false)] = False
_generated_ticket_id: int | None = PrivateAttr(default=None)
_user_id: int = PrivateAttr(default=None)

Expand Down
2 changes: 2 additions & 0 deletions cg/services/orders/validation/models/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def set_null_to_false(value: bool | None) -> bool:
return value if value else False
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,15 @@ def test_null_conversion(valid_order: TomteOrder, model_validator: ModelValidato

# THEN the empty concentration should be converted to None
assert order.cases[0].samples[0].concentration_ng_ul is None


def test_skip_rc_default_conversion(valid_order: TomteOrder, model_validator: ModelValidator):
# GIVEN a Tomte order with skip_reception_control set to None
valid_order.skip_reception_control = None
raw_order: dict = valid_order.model_dump(by_alias=True)

# WHEN validating the order
order, _ = model_validator.validate(order=raw_order, model=TomteOrder)

# THEN the skip_reception_control value should be converted to None
assert order.skip_reception_control is False
Loading