Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add compatibility with documented prior API #65

Merged
merged 1 commit into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading