浏览代码

HUE-8630 [core] Fix install_samples loaddata atomic

jdesjean 7 年之前
父节点
当前提交
918dd21

+ 2 - 1
apps/oozie/src/oozie/management/commands/oozie_setup.py

@@ -363,7 +363,8 @@ class Command(BaseCommand):
     LOG.info(_("Installing examples..."))
 
     if ENABLE_V2.get():
-      management.call_command('loaddata', 'initial_oozie_examples.json', verbosity=2)
+      with transaction.atomic():
+        management.call_command('loaddata', 'initial_oozie_examples.json', verbosity=2, commit=False)
 
     if IS_HUE_4.get():
       # Install editor oozie examples without doc1 link

+ 3 - 3
apps/pig/src/pig/management/commands/pig_setup.py

@@ -129,9 +129,9 @@ STORE upper_case INTO '$output';
     else:
       # Install old pig script fixture
       LOG.info("Using Hue 3, will install pig script fixture.")
-
-      management.call_command('loaddata', 'initial_pig_examples.json', verbosity=2)
-      Document.objects.sync()
+      with transaction.atomic():
+        management.call_command('loaddata', 'initial_pig_examples.json', verbosity=2, commit=False)
+        Document.objects.sync()
 
     if USE_NEW_EDITOR.get():
       # Get or create sample user directories

+ 4 - 2
apps/search/src/search/management/commands/search_setup.py

@@ -19,6 +19,7 @@ import logging
 
 from django.core import management
 from django.core.management.base import BaseCommand
+from django.db import transaction
 
 from desktop.models import Directory, Document, Document2, Document2Permission, SAMPLE_USER_OWNERS
 from useradmin.models import get_default_user_group, install_sample_user
@@ -41,8 +42,9 @@ class Command(BaseCommand):
     )
 
     if not Document2.objects.filter(type='search-dashboard', owner__username__in=SAMPLE_USER_OWNERS).exists():
-      management.call_command('loaddata', 'initial_search_examples.json', verbosity=2)
-      Document.objects.sync()
+      with transaction.atomic():
+        management.call_command('loaddata', 'initial_search_examples.json', verbosity=2, commit=False)
+        Document.objects.sync()
 
       Document2.objects.filter(type='search-dashboard', owner__username__in=SAMPLE_USER_OWNERS).update(parent_directory=examples_dir)
     else:

+ 4 - 2
desktop/libs/notebook/src/notebook/management/commands/notebook_setup.py

@@ -22,6 +22,7 @@ import pwd
 from django.contrib.auth.models import User
 from django.core import management
 from django.core.management.base import BaseCommand
+from django.db import transaction
 
 from desktop.models import Directory, Document, Document2, Document2Permission, SAMPLE_USER_OWNERS
 from useradmin.models import get_default_user_group, install_sample_user
@@ -44,8 +45,9 @@ class Command(BaseCommand):
     if not Document2.objects.filter(uuid="7f2ea775-e067-4fde-8f5f-4d704ab9b002").exists():
       sample_user = install_sample_user()
 
-      management.call_command('loaddata', 'initial_notebook_examples.json', verbosity=2)
-      Document.objects.sync()
+      with transaction.atomic():
+        management.call_command('loaddata', 'initial_notebook_examples.json', verbosity=2, commit=False)
+        Document.objects.sync()
 
       # Get or create sample user directories
       home_dir = Directory.objects.get_home_directory(sample_user)