Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug] CA/Cert creation generates 2 SQL write queries instead of 1 #120

Open
nemesifier opened this issue Jul 18, 2021 · 1 comment · May be fixed by #168
Open

[bug] CA/Cert creation generates 2 SQL write queries instead of 1 #120

nemesifier opened this issue Jul 18, 2021 · 1 comment · May be fixed by #168

Comments

@nemesifier
Copy link
Member

This code:

def save(self, *args, **kwargs):
generate = False
if not self.pk and not self.certificate and not self.private_key:
generate = True
super().save(*args, **kwargs)
if generate:
# automatically determine serial number
if not self.serial_number:
self.serial_number = self._generate_serial_number()
self._generate()
kwargs['force_insert'] = False
super().save(*args, **kwargs)

Generates two queries for creating a certificate and a CA.

I figured this out while working on openwisp/openwisp-controller#455.

I think this part could be optimized.

@SitaGanesh
Copy link

Hi Sir, I'm new to contributing to this project, but I'm eager to join your organization and excited to help out!

I've looked into the issue and believe the root cause is the redundant super().save calls in the save method. To optimize this, we can:

  • This defers the initial super().save call until after generating the certificate and private key.
  • Remove the second super().save call, as it's no longer necessary.

This will reduce database writes and ensure data consistency.

I'm going to dive into a PR to implement this change. Let me know if you have any suggestions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: To do (Python & Django)
2 participants