← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~pappacena/launchpad:fix-product-flush-lock into launchpad:master

 

Thiago F. Pappacena has proposed merging ~pappacena/launchpad:fix-product-flush-lock into launchpad:master.

Commit message:
Refactoring product edit to avoid database lock errors when adding code import (OOPS 273afd4847b8c502c72a2d29ec79b075 in qastaging environment)

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~pappacena/launchpad/+git/launchpad/+merge/386514
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~pappacena/launchpad:fix-product-flush-lock into launchpad:master.
diff --git a/lib/lp/registry/browser/product.py b/lib/lp/registry/browser/product.py
index 71595ee..5b2ce70 100644
--- a/lib/lp/registry/browser/product.py
+++ b/lib/lp/registry/browser/product.py
@@ -2068,10 +2068,6 @@ class ProductSetBranchView(ReturnToReferrerMixin, LaunchpadFormView,
         branch_type = data.get('branch_type')
 
         if not self.is_series:
-            default_vcs = data.get('default_vcs')
-            if default_vcs:
-                self.context.vcs = default_vcs
-
             git_repository_type = data.get('git_repository_type')
 
             if git_repository_type == LINK_LP:
@@ -2105,6 +2101,14 @@ class ProductSetBranchView(ReturnToReferrerMixin, LaunchpadFormView,
             else:
                 raise UnexpectedFormData(git_repository_type)
 
+            # Change self.context data here. CodeImport creation will run
+            # some checks, and this would cause Product object to flush to
+            # database. Under rare situations, this flush could lead to
+            # deadlock condition (see OOPS 273afd4847b8c502c72a2d29ec79b075).
+            default_vcs = data.get('default_vcs')
+            if default_vcs:
+                self.context.vcs = default_vcs
+
         if branch_type == LINK_LP:
             branch_location = data.get('branch_location')
             if branch_location != self.series.branch:

Follow ups