Skip to content

Commit

Permalink
fix(audit): handle case where AuditLog doesn't have a history record (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewelwell committed Jan 31, 2024
1 parent 5e07e40 commit 6501829
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
6 changes: 6 additions & 0 deletions api/audit/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ def environment_document_updated(self) -> bool:

@property
def history_record(self) -> typing.Optional[Model]:
if not (self.history_record_class_path and self.history_record_id):
# There are still AuditLog records that will not have this detail
# for example, audit log records which are created when segment
# override priorities are changed.
return

klass = self.get_history_record_model_class(self.history_record_class_path)
return klass.objects.filter(history_id=self.history_record_id).first()

Expand Down
11 changes: 11 additions & 0 deletions api/tests/unit/audit/test_unit_audit_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,17 @@ def test_audit_log_history_record(mocker):
)


def test_audit_log_history_record_for_audit_log_record_with_no_history_record(mocker):
# Given
audit_log = AuditLog()

# When
record = audit_log.history_record

# Then
assert record is None


def test_audit_log_save_project_is_added_if_not_set(environment):
# Given
audit_log = AuditLog(environment=environment)
Expand Down

0 comments on commit 6501829

Please sign in to comment.