#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 )
- FloatRangeField db data == None
- ./manage dumpdata
- ./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)
Change History (13)
comment:1 by , 9 years ago
Description: | modified (diff) |
---|
comment:2 by , 9 years ago
Cc: | added |
---|
by , 9 years ago
Attachment: | 26215-test.diff added |
---|
follow-up: 4 comment:3 by , 9 years ago
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 , 9 years ago
Attachment: | 26215-test2.diff added |
---|
comment:5 by , 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 ValidationError → FloatRangeField/IntegerRangeField with None as a range boundary doesn't round trip in serialization |
Triage Stage: | Unreviewed → Accepted |
I've understood the problem now and attached a test. Not sure if the proposed fix is correct.
comment:6 by , 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 , 9 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
I tried to reproduce with the attached test but it works fine. Could you provide a failing test?