Skip to content

Commit

Permalink
🐛 Load parent,child samples in validation from db into memory
Browse files Browse the repository at this point in the history
  • Loading branch information
znatty22 committed May 22, 2024
1 parent 463e68c commit cabe3df
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions dataservice/api/sample_relationship/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class SampleRelationship(db.Model, Base):
"""
Represents a relationship between two samples.
The relationship table represents a tree.
The relationship table represents a tree.
:param kf_id: Primary key given by the Kid's First DCC
:param created_at: Time of object creation
Expand Down Expand Up @@ -119,11 +119,12 @@ 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:
# Get samples in relationship by id
parent = Sample.query.get(target.parent_id)
child = Sample.query.get(target.child_id)

# Check that both are existing samples
if not (parent and child):
raise DatabaseValidationError(
SampleRelationship.__tablename__,
"modify",
Expand All @@ -133,8 +134,8 @@ def validate_sample_relationship(target):

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

if sr:
Expand Down

0 comments on commit cabe3df

Please sign in to comment.