Anonymous avatar Anonymous committed 1e1054e

Fix and test for #65: --dry-run causes rename_column to fail

Comments (0)

Files changed (2)

     has_ddl_transactions = False
     def rename_column(self, table_name, old, new):
-        if old == new:
+        if old == new or self.dry_run:
             return []
         qn = connection.ops.quote_name
             self.execute(sql, (rows[0][4],))
     def rename_table(self, old_table_name, table_name):
         Renames the table 'old_table_name' to 'table_name'.
+    def test_dry_rename(self):
+        """
+        Test column renaming while --dry-run is turned on (should do nothing)
+        """
+        cursor = connection.cursor()
+        db.create_table("test2", [('spam', models.BooleanField(default=False))])
+        db.start_transaction()
+        # Make sure we can select the column
+        cursor.execute("SELECT spam FROM test2")
+        # Rename it
+        db.dry_run = True
+        db.rename_column("test2", "spam", "eggs")
+        db.dry_run = False
+        cursor.execute("SELECT spam FROM test2")
+        try:
+            cursor.execute("SELECT eggs FROM test2")
+  "Dry-renamed new column could be selected!")
+        except:
+            pass
+        db.rollback_transaction()
+        db.delete_table("test2")
     def test_table_rename(self):
         Test column renaming
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.