mirror of https://github.com/django/django.git
Fixed #34050 -- Replaced invalid chars in migration names with '_'.
Thanks to Bishal Gautam for the report and initial implementation.
Regression in fa58450a9a
.
Co-Authored-By: Bishal Gautam <bisalgt@gmail.com>
This commit is contained in:
parent
d938b3b257
commit
cd03e8e2d6
|
@ -1,3 +1,5 @@
|
|||
import re
|
||||
|
||||
from django.db.migrations.utils import get_migration_name_timestamp
|
||||
from django.db.transaction import atomic
|
||||
|
||||
|
@ -205,7 +207,7 @@ class Migration:
|
|||
return "initial"
|
||||
|
||||
raw_fragments = [op.migration_name_fragment for op in self.operations]
|
||||
fragments = [name for name in raw_fragments if name]
|
||||
fragments = [re.sub(r"\W+", "_", name) for name in raw_fragments if name]
|
||||
|
||||
if not fragments or len(fragments) != len(self.operations):
|
||||
return "auto_%s" % get_migration_name_timestamp()
|
||||
|
|
|
@ -5314,6 +5314,20 @@ class MigrationSuggestNameTests(SimpleTestCase):
|
|||
migration = Migration("some_migration", "test_app")
|
||||
self.assertIs(migration.suggest_name().startswith("auto_"), True)
|
||||
|
||||
def test_operation_with_invalid_chars_in_suggested_name(self):
|
||||
class Migration(migrations.Migration):
|
||||
operations = [
|
||||
migrations.AddConstraint(
|
||||
"Person",
|
||||
models.UniqueConstraint(
|
||||
fields=["name"], name="person.name-*~unique!"
|
||||
),
|
||||
),
|
||||
]
|
||||
|
||||
migration = Migration("some_migration", "test_app")
|
||||
self.assertEqual(migration.suggest_name(), "person_person_name_unique_")
|
||||
|
||||
def test_none_name(self):
|
||||
class Migration(migrations.Migration):
|
||||
operations = [migrations.RunSQL("SELECT 1 FROM person;")]
|
||||
|
|
Loading…
Reference in New Issue