Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#26215 closed Bug (fixed)

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

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>

Attachments (2)

26215-test.diff (944 bytes ) - added by Tim Graham 9 years ago.
26215-test2.diff (812 bytes ) - added by Tim Graham 9 years ago.

Download all attachments as: .zip

Change History (13)

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.

comment:6 by Claude Paroz, 9 years ago

Patch needs improvement: unset

On that PR, I fixed the problem by changing the serialization in the first place (outputting null instead of 'None' from RangeField.value_to_string).

comment:7 by Tim Graham, 9 years ago

Triage Stage: AcceptedReady for checkin

comment:8 by Claude Paroz, 9 years ago

For the records, this might be a regression introduced by #24937.

comment:9 by Claude Paroz <claude@…>, 9 years ago

Resolution: fixed
Status: newclosed

In 928c12e:

Fixed #26215 -- Fixed RangeField/ArrayField serialization with None values

Also added tests for HStoreField and JSONField.
Thanks Aleksey Bukin for the report and Tim Graham for the initial patch and
the review.

comment:10 by Claude Paroz <claude@…>, 9 years ago

In 205cafd0:

[1.9.x] Fixed #26215 -- Fixed RangeField/ArrayField serialization with None values

Also added tests for HStoreField and JSONField.
Thanks Aleksey Bukin for the report and Tim Graham for the initial patch and
the review.
Backport of 928c12eb1 from master.

comment:11 by Claude Paroz <claude@…>, 9 years ago

In 5bce6659:

[1.8.x] Fixed #26215 -- Fixed RangeField/ArrayField serialization with None values

Also added tests for HStoreField.
Thanks Aleksey Bukin for the report and Tim Graham for the initial patch and
the review.
Backport of 928c12eb1 from master.

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