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(audit): handle case where AuditLog doesn't have a history record #3357

Merged
merged 1 commit into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
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
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
Loading