#22289: Field with Validator always considered changed in migrations
----------------------------+---------------------------------------
     Reporter:  blueyed     |                    Owner:  nobody
         Type:  Bug         |                   Status:  new
    Component:  Migrations  |                  Version:  1.7-alpha-2
     Severity:  Normal      |               Resolution:
     Keywords:              |             Triage Stage:  Unreviewed
    Has patch:  0           |      Needs documentation:  0
  Needs tests:  0           |  Patch needs improvement:  0
Easy pickings:  0           |                    UI/UX:  0
----------------------------+---------------------------------------

Comment (by blueyed):

 Compiled patterns (_sre.SRE_Pattern) are considered to equal/identical for
 the same pattern (from ipyhon shell).

 RegexValidator's `__eq__` only tests for `==` for the SRE_Pattern, which
 fails in my case:

 {{{
 ipdb> v1.regex
 <_sre.SRE_Pattern object at 0x1b0e470>
 ipdb> _v2.regex
 <_sre.SRE_Pattern object at 0x2abbdd0>
 ipdb> _v1.regex == _v2.regex
 False
 ipdb> _v1.regex.
 _v1.regex.findall     _v1.regex.flags       _v1.regex.groups
 _v1.regex.pattern     _v1.regex.search      _v1.regex.sub
 _v1.regex.finditer    _v1.regex.groupindex  _v1.regex.match
 _v1.regex.scanner     _v1.regex.split       _v1.regex.subn
 ipdb> _v1.regex.pattern
 '(?i)^(?:(?:https?://)?www.imdb.com/title/)?(tt\\d+)(?:/.*)?$'
 ipdb> _v2.regex.pattern
 '(?i)^(?:(?:https?://)?www.imdb.com/title/)?(tt\\d+)(?:/.*)?$'
 ipdb> _v2.regex.flags
 2
 ipdb> _v1.regex.flags
 2
 ipdb> pprint(_v1)
 <django.core.validators.RegexValidator object at 0x1aa3350>
 ipdb> pprint(_v1.__dict__)
 {'_constructor_args':
 (('(?i)^(?:(?:https?://)?www.imdb.com/title/)?(tt\\d+)(?:/.*)?$',),
                        {}),
  'regex': <_sre.SRE_Pattern object at 0x1b0e470>}
 ipdb> pprint(_v2.__dict__)
 {'_constructor_args':
 (('(?i)^(?:(?:https?://)?www.imdb.com/title/)?(tt\\d+)(?:/.*)?$',),
                        {}),
  'regex': <_sre.SRE_Pattern object at 0x2abbdd0>}
 }}}

 Maybe `RegexValidator.__eq__` needs to get enhanced, to compare the
 relevant regex attributes?

 I am using Python 2.7.5+ (Ubuntu Linux), on a 64bit.
 Something must causing the SRE_Pattern objects to not get re-used in my
 case.


 {{{
 (full output of all attributes:
 ipdb> [_v1.regex.__getattribute__(x) for x in ['findall', 'finditer',
 'flags', 'groupindex', 'groups', 'match', 'pattern', 'scanner', 'search',
 'split', 'sub', 'subn']]
 [<built-in method findall of _sre.SRE_Pattern object at 0x1b0e470>,
 <built-in method finditer of _sre.SRE_Pattern object at 0x1b0e470>, 2, {},
 1, <built-in method match of _sre.SRE_Pattern object at 0x1b0e470>,
 '(?i)^(?:(?:https?://)?www.imdb.com/title/)?(tt\\d+)(?:/.*)?$', <built-in
 method scanner of _sre.SRE_Pattern object at 0x1b0e470>, <built-in method
 search of _sre.SRE_Pattern object at 0x1b0e470>, <built-in method split of
 _sre.SRE_Pattern object at 0x1b0e470>, <built-in method sub of
 _sre.SRE_Pattern object at 0x1b0e470>, <built-in method subn of
 _sre.SRE_Pattern object at 0x1b0e470>]

 ipdb> [_v2.regex.__getattribute__(x) for x in ['findall', 'finditer',
 'flags', 'groupindex', 'groups', 'match', 'pattern', 'scanner', 'search',
 'split', 'sub', 'subn']]
 [<built-in method findall of _sre.SRE_Pattern object at 0x2abbdd0>,
 <built-in method finditer of _sre.SRE_Pattern object at 0x2abbdd0>, 2, {},
 1, <built-in method match of _sre.SRE_Pattern object at 0x2abbdd0>,
 '(?i)^(?:(?:https?://)?www.imdb.com/title/)?(tt\\d+)(?:/.*)?$', <built-in
 method scanner of _sre.SRE_Pattern object at 0x2abbdd0>, <built-in method
 search of _sre.SRE_Pattern object at 0x2abbdd0>, <built-in method split of
 _sre.SRE_Pattern object at 0x2abbdd0>, <built-in method sub of
 _sre.SRE_Pattern object at 0x2abbdd0>, <built-in method subn of
 _sre.SRE_Pattern object at 0x2abbdd0>]
 )
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/22289#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 django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/065.c75d98d40a6101b4b17757200afc394e%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to