diff options
| author | Brian Helba <brian.helba@kitware.com> | 2022-03-29 19:57:59 -0400 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2022-04-04 07:38:15 +0200 |
| commit | 2d5215c675c2f128f7e9fc296cd5a0a5a527dff4 (patch) | |
| tree | 91e7d771215b21d986ec01bb31d42e01595f8d69 /tests | |
| parent | 13a9cde133ac82e33dd091ca9bb9c677804afbe1 (diff) | |
Fixed #33605 -- Fixed migration crash when altering RegexValidator to pre-compiled regular expression.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/migrations/test_autodetector.py | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/migrations/test_autodetector.py b/tests/migrations/test_autodetector.py index 8ddb339002..0d7a44e42d 100644 --- a/tests/migrations/test_autodetector.py +++ b/tests/migrations/test_autodetector.py @@ -2410,6 +2410,37 @@ class AutodetectorTests(TestCase): self.assertNumberMigrations(changes, "testapp", 1) self.assertOperationTypes(changes, "testapp", 0, ["AlterField"]) + def test_alter_regex_string_to_compiled_regex(self): + regex_string = "^[a-z]+$" + from_state = ModelState( + "testapp", + "model", + [ + ( + "id", + models.AutoField( + primary_key=True, validators=[RegexValidator(regex_string)] + ), + ) + ], + ) + to_state = ModelState( + "testapp", + "model", + [ + ( + "id", + models.AutoField( + primary_key=True, + validators=[RegexValidator(re.compile(regex_string))], + ), + ) + ], + ) + changes = self.get_changes([from_state], [to_state]) + self.assertNumberMigrations(changes, "testapp", 1) + self.assertOperationTypes(changes, "testapp", 0, ["AlterField"]) + def test_empty_foo_together(self): """ #23452 - Empty unique/index_together shouldn't generate a migration. |
