Opened 4 years ago

Closed 4 years ago

Last modified 4 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 4 years ago.
26215-test2.diff (812 bytes) - added by Tim Graham 4 years ago.

Download all attachments as: .zip

Change History (13)

comment:1 Changed 4 years ago by Алексей

Description: modified (diff)

comment:2 Changed 4 years ago by Алексей

Cc: Алексей added

Changed 4 years ago by Tim Graham

Attachment: 26215-test.diff added

comment:3 Changed 4 years ago by Tim Graham

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

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

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

Changed 4 years ago by Tim Graham

Attachment: 26215-test2.diff added

comment:5 Changed 4 years ago by Tim Graham

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 Changed 4 years ago by Claude Paroz

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 Changed 4 years ago by Tim Graham

Triage Stage: AcceptedReady for checkin

comment:8 Changed 4 years ago by Claude Paroz

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

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

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 Changed 4 years ago by Claude Paroz <claude@…>

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 Changed 4 years ago by Claude Paroz <claude@…>

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