From 90552f43d4d6313feefb878b373eabe22bae6457 Mon Sep 17 00:00:00 2001 From: Robert Galloway Date: Fri, 12 Apr 2024 12:22:33 -0700 Subject: [PATCH] fix Account.save() --- src/oscar_accounts/abstract_models.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/oscar_accounts/abstract_models.py b/src/oscar_accounts/abstract_models.py index 35c9535..ed4373a 100644 --- a/src/oscar_accounts/abstract_models.py +++ b/src/oscar_accounts/abstract_models.py @@ -146,8 +146,10 @@ def save(self, *args, **kwargs): if self.code: self.code = self.code.upper() # Ensure the balance is always correct when saving - self.balance = self._balance() - return super().save(*args, **kwargs) + # Django 4.2 requires a pk to use manager methods as in self._balance() + if self.pk is not None: + self.balance = self._balance() + super().save(*args, **kwargs) def _balance(self): aggregates = self.transactions.aggregate(sum=Sum('amount'))