Skip to content

Commit

Permalink
Fixed #336: Score ranges were persisting despite being removed from u…
Browse files Browse the repository at this point in the history
…pdated item
  • Loading branch information
bencap committed Oct 16, 2024
1 parent 2d1c953 commit db5b952
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/mavedb/routers/score_sets.py
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,8 @@ async def update_score_set(

if item_update.score_ranges:
item.score_ranges = item_update.score_ranges.dict()
else:
item.score_ranges = None

# Delete the old target gene, WT sequence, and reference map. These will be deleted when we set the score set's
# target_gene to None, because we have set cascade='all,delete-orphan' on ScoreSet.target_gene. (Since the
Expand Down
20 changes: 16 additions & 4 deletions src/mavedb/view_models/score_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,10 @@ def at_least_one_target_gene_exists(cls, field_value, values):
return field_value

@validator("score_ranges")
def score_range_labels_must_be_unique(cls, field_value: ScoreRanges):
def score_range_labels_must_be_unique(cls, field_value: Optional[ScoreRanges]):
if field_value is None:
return None

existing_labels = []
for i, range_model in enumerate(field_value.ranges):
range_model.label = range_model.label.strip()
Expand All @@ -195,7 +198,10 @@ def score_range_labels_must_be_unique(cls, field_value: ScoreRanges):
return field_value

@validator("score_ranges")
def ranges_contain_normal_and_abnormal(cls, field_value: ScoreRanges):
def ranges_contain_normal_and_abnormal(cls, field_value: Optional[ScoreRanges]):
if field_value is None:
return None

ranges = set([range_model.classification for range_model in field_value.ranges])
if not set(default_ranges).issubset(ranges):
raise ValidationError(
Expand All @@ -207,7 +213,7 @@ def ranges_contain_normal_and_abnormal(cls, field_value: ScoreRanges):
return field_value

@validator("score_ranges")
def ranges_do_not_overlap(cls, field_value: ScoreRanges):
def ranges_do_not_overlap(cls, field_value: Optional[ScoreRanges]):
def test_overlap(tp1, tp2) -> bool:
# Always check the tuple with the lowest lower bound. If we do not check
# overlaps in this manner, checking the overlap of (0,1) and (1,2) will
Expand All @@ -226,6 +232,9 @@ def test_overlap(tp1, tp2) -> bool:

return False

if field_value is None:
return None

for i, range_test in enumerate(field_value.ranges):
for range_check in list(field_value.ranges)[i + 1 :]:
if test_overlap(range_test.range, range_check.range):
Expand All @@ -237,7 +246,10 @@ def test_overlap(tp1, tp2) -> bool:
return field_value

@validator("score_ranges")
def wild_type_score_in_normal_range(cls, field_value: ScoreRanges):
def wild_type_score_in_normal_range(cls, field_value: Optional[ScoreRanges]):
if field_value is None:
return None

normal_ranges = [
range_model.range for range_model in field_value.ranges if range_model.classification == "normal"
]
Expand Down

0 comments on commit db5b952

Please sign in to comment.