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

fix(2079/deadlock): avoid deadlock by updating env individually #3339

Merged
merged 1 commit into from
Jan 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions api/audit/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,16 +116,21 @@ def add_created_date(self) -> None:
is_now=True,
)
def process_environment_update(self):
from environments.models import Environment
from environments.tasks import process_environment_update

environments_filter = Q()
if self.environment_id:
environments_filter = Q(id=self.environment_id)

# Use a queryset to perform update to prevent signals being called at this point.
# Since we're re-saving the environment, we don't want to duplicate signals.
self.project.environments.filter(environments_filter).update(
updated_at=self.created_date
)
environment_ids = self.project.environments.filter(
environments_filter
).values_list("id", flat=True)

# Update environment individually to avoid deadlock
for environment_id in environment_ids:
Environment.objects.filter(id=environment_id).update(
updated_at=self.created_date
)

process_environment_update.delay(args=(self.id,))
Loading