Skip to content

Commit

Permalink
Add compatibility with documented prior API (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanhiebert authored Jul 25, 2024
1 parent a416a23 commit 79a4860
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Pending
* Add support for Django 5.1.
* Drop support for Django 3.2, 4.0, 4.1.
* Convert ``Safe`` to be a custom class rather than an ``Enum``.
* The valid values for ``safe`` are:
* The preferred values for ``safe`` are now methods:

* ``Safe.before_deploy()``
* ``Safe.after_deploy()``
Expand Down
4 changes: 3 additions & 1 deletion src/django_safemigrate/management/commands/safemigrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ class Mode(Enum):

def safety(migration: Migration):
"""Determine the safety status of a migration."""
return getattr(migration, "safe", Safe.always())
safe = getattr(migration, "safe", Safe.always())
callables = [Safe.before_deploy, Safe.after_deploy, Safe.always]
return safe() if safe in callables else safe


def safemigrate_mode():
Expand Down
11 changes: 11 additions & 0 deletions tests/safemigrate_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,17 @@ def test_rerun(self, receiver):
receiver(plan=plan)
assert len(plan) == 1

def test_callable_compat(self, receiver):
"""Understand and do not throw an error when using compatibility syntax."""
# The plan items aren't dependencies of each other.
plan = [
(Migration(safe=Safe.before_deploy), False),
(Migration(safe=Safe.always), False),
(Migration(safe=Safe.after_deploy), False),
]
receiver(plan=plan)
assert len(plan) == 2

def test_backward(self, receiver):
"""It should fail to run backward."""
plan = [(Migration(), True)]
Expand Down

0 comments on commit 79a4860

Please sign in to comment.