Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#23770 closed Bug (fixed)

float("inf") as an argument to a validator breaks migrations

Reported by: w0rp Owned by: Markus Holtermann
Component: Migrations Version: dev
Severity: Release blocker Keywords:
Cc: info+coding@… Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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.

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.

class SomeModel (Model):
    some_field = IntegerField(
        validators= [DoNothingValidator(float("inf"))],
    )

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

...
('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.

Change History (6)

comment:1 by Baptiste Mispelon, 9 years ago

Severity: NormalRelease blocker
Triage Stage: UnreviewedAccepted
Version: 1.7master

Hi,

I can indeed reproduce this.
I'm going to bump the severity of the ticket too.

Thanks for the detailed bug report!

comment:2 by Markus Holtermann, 9 years ago

Cc: info+coding@… added
Owner: changed from nobody to Markus Holtermann
Status: newassigned

comment:3 by Markus Holtermann, 9 years ago

Has patch: set

comment:4 by Baptiste Mispelon, 9 years ago

Triage Stage: AcceptedReady for checkin

Patch looks good (I just have a minor complaint about the alphabetical ordering of imports but that's just cosmetic).

Let's see what the CI has to say.

Thanks!

comment:5 by Baptiste Mispelon <bmispelon@…>, 9 years ago

Resolution: fixed
Status: assignedclosed

In c7c098cf97fbb1416f302c76799058ad63a5f7aa:

Fixed #23770 -- Changed serialization strategy for floats with respect to NaN and Inf

Thanks to w0rp for the report

comment:6 by Baptiste Mispelon <bmispelon@…>, 9 years ago

In 1f50ea730e250acdc9f62f1ce1a769296fc20bb8:

[1.7.x] Fixed #23770 -- Changed serialization strategy for floats with respect to NaN and Inf

Thanks to w0rp for the report

Backport of c7c098cf97fbb1416f302c76799058ad63a5f7aa from master.

Note: See TracTickets for help on using tickets.
Back to Top