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 Fail (bool): History fields not populated
""" """
if not hasattr(model, '_before'): if(
not hasattr(model, '_before')
and self.before == None
):
raise ValidationError( raise ValidationError(
code = 'model_missing_before_data', code = 'model_missing_before_data',
message = 'Unable to save model history as the "before" data is missing.' 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( raise ValidationError(
code = 'model_missing_after_data', code = 'model_missing_after_data',
message = 'Unable to save model history as the "after" data is missing.' 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: if model._before == model._after:
raise ValidationError( raise ValidationError(