#25280: Infinite migrations created when using function based validators
-------------------------------------+-------------------------------------
Reporter: chenull | Owner: MarkusH
Type: Bug | Status: assigned
Component: Migrations | Version: master
Severity: Release blocker | Resolution:
Keywords: migrations, | Triage Stage: Accepted
validators, slug |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by MarkusH):
* has_patch: 0 => 1
Comment:
OK, I this is just an idea, and the current tests on master work, but I
don't have a test that doesn't work on master yet ;)
{{{#!diff
diff --git a/django/db/migrations/autodetector.py
b/django/db/migrations/autodetector.py
index 41830f0..1509fa7 100644
--- a/django/db/migrations/autodetector.py
+++ b/django/db/migrations/autodetector.py
@@ -11,6 +11,7 @@ from django.db.migrations.migration import Migration
from django.db.migrations.operations.models import AlterModelOptions
from django.db.migrations.optimizer import MigrationOptimizer
from django.db.migrations.questioner import MigrationQuestioner
+from django.db.migrations.utils import COMPILED_REGEX_TYPE, RegexObject
from django.utils import six
from .topological_sort import stable_topological_sort
@@ -62,6 +63,8 @@ class MigrationAutodetector(object):
key: self.deep_deconstruct(value)
for key, value in obj.items()
}
+ elif isinstance(obj, COMPILED_REGEX_TYPE):
+ return RegexObject(obj.pattern, obj.flags)
elif isinstance(obj, type):
# If this is a type that implements 'deconstruct' as an
instance method,
# avoid treating this as being deconstructible itself - see
#22951
diff --git a/django/db/migrations/utils.py b/django/db/migrations/utils.py
new file mode 100644
index 0000000..412db15
--- /dev/null
+++ b/django/db/migrations/utils.py
@@ -0,0 +1,12 @@
+import re
+
+COMPILED_REGEX_TYPE = type(re.compile(''))
+
+
+class RegexObject(object):
+ def __init__(self, pattern, flags):
+ self.pattern = pattern
+ self.flags = flags
+
+ def __eq__(self, other):
+ return self.pattern == other.pattern and self.flags ==
other.flags
diff --git a/django/db/migrations/writer.py
b/django/db/migrations/writer.py
index 44a4017..fb6a162 100644
--- a/django/db/migrations/writer.py
+++ b/django/db/migrations/writer.py
@@ -14,6 +14,7 @@ from django.apps import apps
from django.db import migrations, models
from django.db.migrations.loader import MigrationLoader
from django.db.migrations.operations.base import Operation
+from django.db.migrations.utils import COMPILED_REGEX_TYPE, RegexObject
from django.utils import datetime_safe, six
from django.utils._os import upath
from django.utils.encoding import force_text
@@ -23,8 +24,6 @@ from django.utils.module_loading import module_dir
from django.utils.timezone import utc
from django.utils.version import get_docs_version
-COMPILED_REGEX_TYPE = type(re.compile(''))
-
class SettingsReference(str):
"""
@@ -506,7 +505,7 @@ class MigrationWriter(object):
format = "(%s)" if len(strings) != 1 else "(%s,)"
return format % (", ".join(strings)), imports
# Compiled regex
- elif isinstance(value, COMPILED_REGEX_TYPE):
+ elif isinstance(value, (COMPILED_REGEX_TYPE, RegexObject)):
imports = {"import re"}
regex_pattern, pattern_imports = cls.serialize(value.pattern)
regex_flags, flag_imports = cls.serialize(value.flags)
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/25280#comment:7>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/065.5bdc365071f6c109b3650d75647abf72%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.