Skip to content

Commit

Permalink
✅ Test sample_relationshp model
Browse files Browse the repository at this point in the history
  • Loading branch information
znatty22 committed May 20, 2024
1 parent ca40242 commit 2044070
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions dataservice/api/sample_relationship/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,22 @@ def validate_sample_relationship(target):
if not target:
return

# Ensure relationship includes existing Samples
try:
parent_id = target.child.kf_id
child_id = target.parent.kf_id
except AttributeError:
raise DatabaseValidationError(
SampleRelationship.__tablename__,
"modify",
"Both parent sample and child sample must point to existing"
f" samples"
)

# Check for reverse relation
sr = SampleRelationship.query.filter_by(
parent_id=target.child.kf_id,
child_id=target.parent.kf_id,
parent_id=parent_id,
child_id=child_id,
).first()

if sr:
Expand All @@ -130,7 +142,7 @@ def validate_sample_relationship(target):
f"Parent: {sr.parent_id} -> Child: {sr.child_id}, already exists"
)

# Check for parent = child
# Check for parent = child
if target.parent.kf_id == target.child.kf_id:
raise DatabaseValidationError(
SampleRelationship.__tablename__,
Expand Down

0 comments on commit 2044070

Please sign in to comment.