#23770: float("inf") as an argument to a validator breaks migrations
----------------------------+--------------------
     Reporter:  w0rp        |      Owner:  nobody
         Type:  Bug         |     Status:  new
    Component:  Migrations  |    Version:  1.7
     Severity:  Normal      |   Keywords:
 Triage Stage:  Unreviewed  |  Has patch:  0
Easy pickings:  0           |      UI/UX:  0
----------------------------+--------------------
 Deconstructing {{{float("inf")}}} in validator arguments breaks
 migrations, probably because {{{repr(float("inf")) == "inf"}}}. A similar
 issue will exist for {{{float("nan")}}}.

 To reproduce this, you'll need a validator using deconstructible.

 {{{#!python
 from django.utils.deconstruct import deconstructible

 @deconstructible
 class DoNothingValidator (object):
     def __init__(self, foo):
         self.foo = foo

     def __call__(self, value):
         pass

     def __eq__(self, other):
         return type(self) == type(other) \
         and self.foo == other.foo
 }}}

 Now you'll need to pass the validator with float("inf") to a field.

 {{{#!python
 class SomeModel (Model):
     some_field = IntegerField(
         validators= [DoNothingValidator(float("inf"))],
     )
 }}}

 Now if you run 'makemigrations', you will get output like the following.

 {{{#!python
 ...
 ('some_field',
 models.IntegerField(validators=[some.path.DoNothingValidator(inf)])),
 ...
 }}}

 The {{{inf}}} above will cause a NameError when you attempt to migrate, or
 when you create further migrations with 'makemigrations' again.

--
Ticket URL: <https://code.djangoproject.com/ticket/23770>
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/047.4c52a6123b30393f314b19b37301ffe1%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to