Skip to content

Commit

Permalink
fix events create
Browse files Browse the repository at this point in the history
  • Loading branch information
sainak committed Sep 26, 2024
1 parent 11b62ee commit 3c9d5d0
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions care/utils/event_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,24 @@ def get_changed_fields(old: Model, new: Model) -> set[str]:
def serialize_field(obj: Model, field_name: str):
if "__" in field_name:
field_name, sub_field = field_name.split("__", 1)
related_object = getattr(obj, field_name, None)
return serialize_field(related_object, sub_field)
related_obj = getattr(obj, field_name, None)
return serialize_field(related_obj, sub_field)

Check warning on line 28 in care/utils/event_utils.py

View check run for this annotation

Codecov / codecov/patch

care/utils/event_utils.py#L27-L28

Added lines #L27 - L28 were not covered by tests

value = None
try:
value = getattr(object, field_name)
value = getattr(obj, field_name)

Check warning on line 32 in care/utils/event_utils.py

View check run for this annotation

Codecov / codecov/patch

care/utils/event_utils.py#L32

Added line #L32 was not covered by tests
except AttributeError:
if object is not None:
if obj is not None:
logger.warning(
"Field %s not found in %s", field_name, object.__class__.__name__
"Field %s not found in %s", field_name, obj.__class__.__name__
)
return None

try:
# serialize choice fields with display value
field = object._meta.get_field(field_name) # noqa: SLF001
field = obj._meta.get_field(field_name) # noqa: SLF001

Check warning on line 42 in care/utils/event_utils.py

View check run for this annotation

Codecov / codecov/patch

care/utils/event_utils.py#L42

Added line #L42 was not covered by tests
if issubclass(field.__class__, Field) and field.choices:
value = getattr(object, f"get_{field_name}_display", lambda: value)()
value = getattr(obj, f"get_{field_name}_display", lambda: value)()
except FieldDoesNotExist:
# the required field is a property and not a model field
pass
Expand Down

0 comments on commit 3c9d5d0

Please sign in to comment.