fix(core): Before attempting to get model audit data confirm fields dont already exist

ref: #783
This commit is contained in:
2025-06-03 09:32:35 +09:30
parent 91b33be834
commit 9dc2114258

View File

@ -149,20 +149,34 @@ class CenturionAudit(
Fail (bool): History fields not populated
"""
if not hasattr(model, '_before'):
if(
not hasattr(model, '_before')
and self.before == None
):
raise ValidationError(
code = 'model_missing_before_data',
message = 'Unable to save model history as the "before" data is missing.'
)
if not hasattr(model, '_after'):
if(
not hasattr(model, '_after')
and self.after == None
):
raise ValidationError(
code = 'model_missing_after_data',
message = 'Unable to save model history as the "after" data is missing.'
)
if(
self.before is not None
and self.after is not None
):
return True
if model._before == model._after:
raise ValidationError(