From 9dc211425824a977e7c4f0dd0fb6100b3dc57096 Mon Sep 17 00:00:00 2001 From: Jon Date: Tue, 3 Jun 2025 09:32:35 +0930 Subject: [PATCH] fix(core): Before attempting to get model audit data confirm fields dont already exist ref: #783 --- app/core/models/audit.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/app/core/models/audit.py b/app/core/models/audit.py index 4f57bccd..f5aa8839 100644 --- a/app/core/models/audit.py +++ b/app/core/models/audit.py @@ -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(