Skip to content

Commit

Permalink
Fix #53 -- Address improper handling of rename operation questioning.
Browse files Browse the repository at this point in the history
  • Loading branch information
charettes committed Jan 24, 2025
1 parent 3c8cbaa commit a8b6fa8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- Add support for Django 5.2 and Python 3.13.
- Drop support for Python 3.8.
- Ensure staged renames and alters are properly serialized. (#52)
- Address improper handling of rename operation questioning. (#53)

1.1.0
=====
Expand Down
12 changes: 6 additions & 6 deletions syzygy/autodetector.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def add_operation(self, app_label, operation, dependencies=None, beginning=False
),
file=sys.stderr,
)
choice = self.questioner.defaults.get("ask_rename_field_stage", 0)
choice = self.questioner.defaults.get("ask_rename_field_stage", 1)
if self.has_interactive_questionner:
choice = self.questioner._choice_input(
"Please choose an appropriate action to take:",
Expand All @@ -113,10 +113,10 @@ def add_operation(self, app_label, operation, dependencies=None, beginning=False
),
],
)
if choice == 0:
if choice == 1:
sys.exit(3)
else:
stage = Stage.PRE_DEPLOY if choice == 1 else Stage.POST_DEPLOY
stage = Stage.PRE_DEPLOY if choice == 2 else Stage.POST_DEPLOY
operation = RenameField.for_stage(operation, stage)
if isinstance(operation, operations.RenameModel):
from_db_table = (
Expand All @@ -135,7 +135,7 @@ def add_operation(self, app_label, operation, dependencies=None, beginning=False
),
file=sys.stderr,
)
choice = self.questioner.defaults.get("ask_rename_model_stage", 0)
choice = self.questioner.defaults.get("ask_rename_model_stage", 1)
if self.has_interactive_questionner:
choice = self.questioner._choice_input(
"Please choose an appropriate action to take:",
Expand All @@ -161,10 +161,10 @@ def add_operation(self, app_label, operation, dependencies=None, beginning=False
),
],
)
if choice == 0:
if choice == 1:
sys.exit(3)
else:
stage = Stage.PRE_DEPLOY if choice == 1 else Stage.POST_DEPLOY
stage = Stage.PRE_DEPLOY if choice == 2 else Stage.POST_DEPLOY
operation = RenameModel.for_stage(operation, stage)
elif isinstance(operation, operations.AlterField) and not operation.field.null:
# Addition of not-NULL constraints must be performed post-deployment.
Expand Down
8 changes: 4 additions & 4 deletions tests/test_autodetector.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,14 +230,14 @@ def test_field_rename(self):
with captured_stderr(), self.assertRaisesMessage(SystemExit, "3"):
self.get_changes(from_models, to_models, questioner)["tests"]
# Pre-deploy rename.
questioner.defaults["ask_rename_field_stage"] = 1
questioner.defaults["ask_rename_field_stage"] = 2
with captured_stderr():
changes = self.get_changes(from_models, to_models, questioner)["tests"]
self.assertEqual(len(changes), 1)
self.assertEqual(get_migration_stage(changes[0]), Stage.PRE_DEPLOY)
self.assertIsInstance(changes[0].operations[0], RenameField)
# Post-deploy rename.
questioner.defaults["ask_rename_field_stage"] = 2
questioner.defaults["ask_rename_field_stage"] = 3
with captured_stderr():
changes = self.get_changes(from_models, to_models, questioner)["tests"]
self.assertEqual(len(changes), 1)
Expand Down Expand Up @@ -271,14 +271,14 @@ def test_model_rename(self):
with captured_stderr(), self.assertRaisesMessage(SystemExit, "3"):
self.get_changes(from_models, to_models, questioner)["tests"]
# Pre-deploy rename.
questioner.defaults["ask_rename_model_stage"] = 1
questioner.defaults["ask_rename_model_stage"] = 2
with captured_stderr():
changes = self.get_changes(from_models, to_models, questioner)["tests"]
self.assertEqual(len(changes), 1)
self.assertEqual(get_migration_stage(changes[0]), Stage.PRE_DEPLOY)
self.assertIsInstance(changes[0].operations[0], RenameModel)
# Post-deploy rename.
questioner.defaults["ask_rename_model_stage"] = 2
questioner.defaults["ask_rename_model_stage"] = 3
with captured_stderr():
changes = self.get_changes(from_models, to_models, questioner)["tests"]
self.assertEqual(len(changes), 1)
Expand Down

0 comments on commit a8b6fa8

Please sign in to comment.