diff --git a/django/db/migrations/writer.py b/django/db/migrations/writer.py
index dbeaae1..f835562 100644
|
a
|
b
|
from django.utils.encoding import force_text
|
| 18 | 18 | from django.utils.functional import Promise |
| 19 | 19 | |
| 20 | 20 | |
| 21 | | COMPILED_REGEX_TYPE = type(re.compile('')) |
| | 21 | BASE_REGEX = re.compile('') |
| | 22 | COMPILED_REGEX_TYPE = type(BASE_REGEX) |
| 22 | 23 | |
| 23 | 24 | |
| 24 | 25 | class SettingsReference(str): |
| … |
… |
class MigrationWriter(object):
|
| 356 | 357 | imports.update(pattern_imports) |
| 357 | 358 | imports.update(flag_imports) |
| 358 | 359 | args = [regex_pattern] |
| 359 | | if value.flags: |
| | 360 | if value.flags != BASE_REGEX.flags: |
| 360 | 361 | args.append(regex_flags) |
| 361 | 362 | return "re.compile(%s)" % ', '.join(args), imports |
| 362 | 363 | # Uh oh. |
diff --git a/tests/migrations/test_writer.py b/tests/migrations/test_writer.py
index 539c201..00da1cb 100644
|
a
|
b
|
class WriterTests(TestCase):
|
| 128 | 128 | """ |
| 129 | 129 | Make sure compiled regex can be serialized. |
| 130 | 130 | """ |
| | 131 | regex = re.compile(r'^\w+$', 0) |
| | 132 | self.assertSerializedEqual(regex) |
| | 133 | |
| 131 | 134 | regex = re.compile(r'^\w+$', re.U) |
| 132 | 135 | self.assertSerializedEqual(regex) |
| 133 | 136 | |
| … |
… |
class WriterTests(TestCase):
|
| 142 | 145 | self.serialize_round_trip(validator) |
| 143 | 146 | |
| 144 | 147 | # Test with a compiled regex. |
| 145 | | validator = RegexValidator(regex=re.compile(r'^\w+$', re.U)) |
| | 148 | validator = RegexValidator(regex=re.compile(r'^\w+$')) |
| 146 | 149 | string = MigrationWriter.serialize(validator)[0] |
| 147 | | self.assertEqual(string, "django.core.validators.RegexValidator(regex=re.compile('^\\\\w+$', 32))") |
| | 150 | self.assertEqual(string, "django.core.validators.RegexValidator(regex=re.compile('^\\\\w+$'))") |
| 148 | 151 | self.serialize_round_trip(validator) |
| 149 | 152 | |
| 150 | 153 | # Test a string regex with flag |