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 committed Feb 4, 2024
1 parent 07f60df commit ba498c3
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion modelcluster/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,17 @@ 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} to '{to_field}'."
.format(
from_field=subject_model._meta.app_label + '.' + field.name,
to_field=field_name,
)
)
try:
field = subject_model._meta.get_field(field_name)
except FieldDoesNotExist:
Expand Down

0 comments on commit ba498c3

Please sign in to comment.