Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix events create #2501

Merged
merged 1 commit into from
Sep 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 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
Loading