Conversation
cg/services/orders/validation/order_types/rna_fusion/models/sample.py
Outdated
Show resolved
Hide resolved
cg/services/orders/validation/order_types/rna_fusion/models/sample.py
Outdated
Show resolved
Hide resolved
|
| def default_and_validate_tumour(cls, v) -> bool: | ||
| """Ensure that the tumour field is always set to True. | ||
| If it is not provided, it defaults to True. | ||
| If it is provided and not True, raise a ValueError. | ||
| """ | ||
| if v is None: | ||
| return True | ||
| if v is not True: | ||
| raise ValueError("Can't perform RNAFUSION analysis on non-tumour samples") | ||
| return v |
There was a problem hiding this comment.
we might want this to fail even if is None
| def __setattr__(self, name, value): | ||
| if name == "tumour" and hasattr(self, name): | ||
| raise ValueError(TUMOUR_ERROR_MESSAGE) | ||
| super().__setattr__(name, value) | ||
|
|
||
| def model_copy(self, *args, update=None, **kwargs): | ||
| if update and "tumour" in update and update["tumour"] is not True: | ||
| raise ValueError(TUMOUR_ERROR_MESSAGE) | ||
| return super().model_copy(*args, update=update, **kwargs) |
There was a problem hiding this comment.
Is this really needed? The RNAFusionSample is like a DTO which is never modified
| if not errors.is_empty: | ||
| LOG.error(errors.get_error_message()) | ||
| raise OrderValidationError(message="Order contained errors") | ||
| raise OrderValidationError(message=errors.get_error_message()) |
There was a problem hiding this comment.
Is this too crazy @islean? This will improve the error message
There was a problem hiding this comment.
If we do that change, we should remove the logging of the error above though? Now we will just have the same thing twice.
There was a problem hiding this comment.
The thing is, this message is the one the customer sees, not the logging. So during the tests, I got "Order contained errors" in the order portal, which is very confusing if you don't know what is wrong with your order
There was a problem hiding this comment.
Oh, but this is not something that the customer can address either way, since the error concerns a field which is not editable for them. So I would say it is not an issue that the "Order contained errors" is nondescript.
There was a problem hiding this comment.
It is editable in the order form
There was a problem hiding this comment.
they also could pick up an existing non-tumour sample
There was a problem hiding this comment.
How can they edit the tumour status? Or you mean that they can do it in the Excel form? Will we even persist that?
There was a problem hiding this comment.
Might be worth to inform about existing samples, although I feel that would be better as a filter in the endpoint for fetching old samples
| def test_set_tumour_to_false_fails_rnafusion_sample(rnafusion_order_to_submit: dict): | ||
| """Test that setting tumour to False for a RNAFUSION sample raises an error.""" | ||
| # GIVEN a parsed RNAFUSION order | ||
| order, _ = ModelValidator.validate(order=rnafusion_order_to_submit, model=RNAFusionOrder) | ||
|
|
||
| # WHEN setting the tumour field to False for a RNAFUSION sample | ||
|
|
||
| # THEN it should raise a ValueError saying that RNAFUSION samples must be tumour samples | ||
| with pytest.raises(ValueError) as exc_info: | ||
| order.cases[0].samples[0].tumour = False | ||
| assert str(exc_info.value) == "RNAFUSION samples must always be tumour samples" |
There was a problem hiding this comment.
If we remove the overriden functions in RNAFusionSample, this test might not be needed anymore
| class ExistingRNAFusionSample(ExistingSample): | ||
| """Model with special tumour validation for existing RNAFUSION samples.""" | ||
|
|
||
| tumour: bool = True |
There was a problem hiding this comment.
I think we want this to be an internal attribute which customers can not access at all. Then we can type hint it as a literal True. Or we simply remove it from the model. Leaving it open for modification just makes it necessary to add all these validators. If we call it _tumour, customers can not modify it: https://docs.pydantic.dev/latest/concepts/models/#private-model-attributes
There was a problem hiding this comment.
That is a great suggestion, I will try to implement it 👍
There was a problem hiding this comment.
The problem is we want an error to be shown to the customer if they try to use non-tumour samples
There was a problem hiding this comment.
Then we need to design how it should look. Given that the tumour status is not rendered for new samples it should likely be in the sample_errors or something of the case?
There was a problem hiding this comment.
Just noticed that this is the existing sample. We should fetch tumour status from statusDB for existing samples IMO
There was a problem hiding this comment.
Just remembered - we could add a warning that we have overruled the tumour status, similar to what was done for the capture kit here
| source: str | ||
| subject_id: str = Field(pattern=NAME_PATTERN, min_length=1, max_length=128) | ||
| tissue_block_size: TissueBlockEnum | None = None | ||
| tumour: bool = True |
There was a problem hiding this comment.
This model is for new samples which currently do not have a tumour field in the order portal. We should either align them or make the field private



Description
Closes #4528
Closes #4530
This PR adds validation to RNAFUSION samples so that they are always tumour
Added
tumourfield in theRNAFusionSampledefaulting toTrue__setattr__method of theRNAFusionSampleso that it raises an error if tumour is set to Falsemodel_copymethod of theRNAFusionSampleso that it raises an error if tumour is set to False when updatingHow to prepare for test
uspaxaHow to test
Submit an RNAFUSION order through the order portal using an existing normal (non-tumour) sample -> verify that it raises an error with a meaningful message
Submit an RNAFUSION order using the order form specifying false as tumour status -> verify that it raises an error with a meaningful message (not very meaningful message, is there something we can do about this? @islean )
Review
Thanks for filling in who performed the code review and the test!
This version is a
Implementation Plan