RegexValidator needs support for flags passed to `re.compile` (migrations do not allow for compiled patterns)
|Reported by:||blueyed||Owned by:||dekomote|
|Cc:||dekomote||Triage Stage:||Ready for checkin|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
When using a RegexValidator with a compiled pattern, makemigration fails:
ValueError: Cannot serialize: <_sre.SRE_Pattern object at 0x24e8ac0>
A sample model:
from django.core.validators import RegexValidator pattern = re.compile(r'foo', re.IGNORECASE) validator = RegexValidator(pattern) class Model(models.Model): foo = models.CharField( validators = [validator], ... )
This is somehow expected, and when passing in the pattern uncompiled it works.
But this won't allow to use re.IGNORE_CASE or other flags for re.compile anymore.
RegexValidator should support a new argument flags, which would then be used for non-compiled patterns (passed on to re.compile).
Let me know, if I could provide a pull request / patch for this (as far as I can see) trivial change.
(It seems like with the new migrations, supporting a pre-compiled pattern is not really relevant anymore (but could be kept still))
(I found this related commit: https://github.com/django/django/commit/e565e1332ddfbb44fe7e6139375e3c243af7398d)
Change History (10)
comment:1 Changed 15 months ago by blueyed
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset
comment:2 Changed 15 months ago by erikr
- Easy pickings set
- Triage Stage changed from Unreviewed to Accepted
- Type changed from Bug to Cleanup/optimization
comment:3 Changed 15 months ago by dekomote
- Owner changed from nobody to dekomote
- Status changed from new to assigned
comment:6 Changed 15 months ago by blueyed
- Triage Stage changed from Accepted to Ready for checkin
- Type changed from Cleanup/optimization to Bug
comment:9 Changed 14 months ago by Erik Romijn <erik@…>
- Resolution set to fixed
- Status changed from assigned to closed