Commits

andrew  committed cae9181

[svn r126] #55: Delay post_syncdb signal. Possibly backwards-incompatable change.

  • Participants
  • Parent commits d9070af
  • Branches trunk

Comments (0)

Files changed (2)

File db/generic.py

         self.debug = False
         self.deferred_sql = []
         self.dry_run = False
+        self.pending_create_signals = []
 
     def execute(self, sql, params=[]):
         """
         Resets the deferred_sql list to empty.
         """
         self.deferred_sql = []
+    
+    
+    def clear_run_data(self):
+        """
+        Resets variables to how they should be before a run. Used for dry runs.
+        """
+        self.clear_deferred_sql()
+        self.pending_create_signals = []
 
 
     def create_table(self, table_name, fields):
 
 
     def send_create_signal(self, app_label, model_names):
+        self.pending_create_signals.append((app_label, model_names))
+
+
+    def send_pending_create_signals(self):
+        for (app_label, model_names) in self.pending_create_signals:
+            self.really_send_create_signal(app_label, model_names)
+        self.pending_create_signals = []
+
+
+    def really_send_create_signal(self, app_label, model_names):
         """
         Sends a post_syncdb signal for the model specified.
 

File migration.py

                     print " ! Error found during dry run of migration! Aborting."
                     return False
                 db.debug = old_debug
-                db.clear_deferred_sql()
+                db.clear_run_data()
             
             db.dry_run = bool(db_dry_run)
             
                 result = run_forwards(mapp, [mname], fake=fake, db_dry_run=db_dry_run, silent=silent)
                 if result is False: # The migrations errored, but nicely.
                     return
+        # Call any pending post_syncdb signals
+        db.send_pending_create_signals()
         # Now load initial data, only if we're really doing things and ended up at current
         if not fake and not db_dry_run and load_inital_data and target_name == migrations[-1]:
             print " - Loading initial data for %s." % app_name