Skip to content

Commit

Permalink
Patch skip rc (#4146)(patch)
Browse files Browse the repository at this point in the history
## Description

Sometimes skip reception control gets sent as None. This gets converted to False now.

### Fixed

- skip_reception_control gets converted to False if null
  • Loading branch information
islean authored Jan 23, 2025
1 parent aac9406 commit 016d4d7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
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
12 changes: 12 additions & 0 deletions tests/services/orders/validation_service/test_model_validator.py
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

0 comments on commit 016d4d7

Please sign in to comment.