Skip to content

Commit

Permalink
Validate relationships data as a list before testing type (closes #397)
Browse files Browse the repository at this point in the history
  • Loading branch information
ml-evs committed Jul 10, 2020
1 parent cf50cf3 commit 2b4c3bd
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion optimade/models/entries.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ class TypedRelationship(Relationship):
# This may be updated when moving to Python 3.8
@validator("data")
def check_rel_type(cls, data):
if hasattr(cls, "_req_type") and any(obj.type != cls._req_type for obj in data):
if not isinstance(data, list):
raise ValueError("`data` key in a relationship must always store a list.")
if hasattr(cls, "_req_type") and any(
getattr(obj, "type", None) != cls._req_type for obj in data
):
raise ValueError("Object stored in relationship data has wrong type")
return data

Expand Down

0 comments on commit 2b4c3bd

Please sign in to comment.