From 00723a0f816ecc29eaf04f768d8a8a4700e5fd9a Mon Sep 17 00:00:00 2001 From: Sita Ganesh Date: Wed, 1 Jan 2025 23:12:08 +0530 Subject: [PATCH] Fixed redundant SQL query during CA cert creation #168 --- django_x509/base/models.py | 1 + django_x509/tests/test_cert.py | 1 + 2 files changed, 2 insertions(+) diff --git a/django_x509/base/models.py b/django_x509/base/models.py index 85ad706..021dfef 100644 --- a/django_x509/base/models.py +++ b/django_x509/base/models.py @@ -201,6 +201,7 @@ def clean(self): def save(self, *args, **kwargs): if not self.pk and not self.certificate and not self.private_key: + #removed these lines and any reference to the generate variable if not self.serial_number: self.serial_number = self._generate_serial_number() self._generate() diff --git a/django_x509/tests/test_cert.py b/django_x509/tests/test_cert.py index c519400..91e1817 100644 --- a/django_x509/tests/test_cert.py +++ b/django_x509/tests/test_cert.py @@ -82,6 +82,7 @@ class TestCert(TestX509Mixin, TestCase): """ def test_new(self): + #added assertNumQueries to check the number of queries made with self.assertNumQueries(3): # 3 query to be made cert = self._create_cert() self.assertNotEqual(cert.certificate, '')