Opened 9 years ago

Last modified 9 years ago

#26215 closed Bug

FloatRangeField/IntegerRangeField with None as a range boundary doesn't round trip in serialization — at Version 5

Reported by: Алексей Owned by: nobody
Component: contrib.postgres Version: 1.9
Severity: Normal Keywords:
Cc: Алексей 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 (last modified by Tim Graham)

  1. FloatRangeField db data == None
  2. ./manage dumpdata
  3. ./manage loaddata

Conversion problem. accept string u'None' to float type

Traceback:

  File "/local/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 1803, in to_python
    params={'value': value},

Decision:

    def to_python(self, value):
        if value == u'None':
            return None
        elif value is None:
            return value
        try:
            return float(value)
        except (TypeError, ValueError):
            raise exceptions.ValidationError(
                self.error_messages['invalid'],
                code='invalid',
                params={'value': value},
            )

And IntegerField too

Source data dump example:

<field name="rate" type="FloatRangeField">{"upper": "None", "lower": "1.45", "bounds": "[)"}</field>

Change History (7)

comment:1 by Алексей, 9 years ago

Description: modified (diff)

comment:2 by Алексей, 9 years ago

Cc: Алексей added

by Tim Graham, 9 years ago

Attachment: 26215-test.diff added

comment:3 by Tim Graham, 9 years ago

I tried to reproduce with the attached test but it works fine. Could you provide a failing test?

in reply to:  3 comment:4 by Алексей, 9 years ago

Replying to timgraham:

I tried to reproduce with the attached test but it works fine. Could you provide a failing test?

Sorry.
I do not write the test so far.

I did everything manually via console.
You test field DateRange and DateTimeTZRange

But i used FloatRangeField and IntegerRangeField and xml format.
Please try these

by Tim Graham, 9 years ago

Attachment: 26215-test2.diff added

comment:5 by Tim Graham, 9 years ago

Component: Database layer (models, ORM)contrib.postgres
Description: modified (diff)
Has patch: set
Patch needs improvement: set
Summary: if dumpdata FloatRangeField and IntegerRangeField values = "None" and post loaddata is ValidationErrorFloatRangeField/IntegerRangeField with None as a range boundary doesn't round trip in serialization
Triage Stage: UnreviewedAccepted

I've understood the problem now and attached a test. Not sure if the proposed fix is correct.

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