Browse Source

added transaction atomic. (#12255)

Lauryn Brown 6 years ago
parent
commit
5c5d2c978f
1 changed files with 10 additions and 9 deletions
  1. 10 9
      bin/load-mocks

+ 10 - 9
bin/load-mocks

@@ -450,15 +450,16 @@ def main(num_events=1, extra_events=False):
             raw_commits = generate_commits(user)
 
             try:
-                repo, _ = Repository.objects.get_or_create(
-                    organization_id=org.id,
-                    provider='integrations:github',
-                    external_id='example/example',
-                    defaults={
-                        'name': 'Example Repo',
-                        'url': 'https://github.com/example/example',
-                    }
-                )
+                with transaction.atomic():
+                    repo, _ = Repository.objects.get_or_create(
+                        organization_id=org.id,
+                        provider='integrations:github',
+                        external_id='example/example',
+                        defaults={
+                            'name': 'Example Repo',
+                            'url': 'https://github.com/example/example',
+                        }
+                    )
             except IntegrityError:
                 # for users with legacy github plugin
                 # upgrade to the new integration