Skip to content

Commit

Permalink
Use log.exception to log exceptions.
Browse files Browse the repository at this point in the history
  - Also set exc_info=True to ensure structlog deals with the stack trace.
  • Loading branch information
terjekv authored and Terje Kvernes committed Dec 5, 2023
1 parent 6be95d6 commit 0e09dbb
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions mreg/api/v1/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,10 @@ def save_log(self, action, serializer, data, orig_data=None):
data=json_data,
)

# We should never fail at performing a clean on the testdata itself.
try:
history.full_clean()
except ValidationError as e:
log.error(ErrorLogObject(None, e, None))
log.exception("ValidationError", e=e, exc_info=True)
return
history.save()

Expand Down Expand Up @@ -100,11 +99,10 @@ def save_log_m2m_alteration(self, method, instance):
data=data,
)

# We should never fail at performing a clean on the testdata itself.
try:
history.full_clean()
except ValidationError as e:
log.error(ErrorLogObject(None, e, None))
log.exception("ValidationError", e=e, exc_info=True)
return
history.save()

Expand Down

0 comments on commit 0e09dbb

Please sign in to comment.