Skip to content

Commit

Permalink
Update get_model_field() to raise a clear error when relationship tra…
Browse files Browse the repository at this point in the history
…versal isn't possible
  • Loading branch information
ababic authored and gasman committed Feb 21, 2024
1 parent 44be4f4 commit 99f685a
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion modelcluster/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,18 @@ def get_model_field(model, name):
subject_model=subject_model,
)
)
if hasattr(field, "related_model"):
if getattr(field, "related_model", None):
traversals.append(TraversedRelationship(subject_model, field))
subject_model = field.related_model
else:
raise FieldDoesNotExist(
"Failed attempting to traverse from {from_field} (a {from_field_type}) to '{to_field}'."
.format(
from_field=subject_model._meta.label + '.' + field.name,
from_field_type=type(field),
to_field=field_name,
)
)
try:
field = subject_model._meta.get_field(field_name)
except FieldDoesNotExist:
Expand Down

0 comments on commit 99f685a

Please sign in to comment.