Conversion problem. accept string u'None' to float type
Track:
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 int(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>
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/26215>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
Old description:
New description:
1. FloatRangeField db data == None
2. ./manage dumpdata
3. ./manage loaddata
Conversion problem. accept string u'None' to float type
Track:
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>
}}}
--
--
Ticket URL: <https://code.djangoproject.com/ticket/26215#comment:1>
* cc: bukin242 (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/26215#comment:2>
* Attachment "26215-test.diff" added.
Comment (by timgraham):
I tried to reproduce with the attached test but it works fine. Could you
provide a failing test?
--
Ticket URL: <https://code.djangoproject.com/ticket/26215#comment:3>
Comment (by bukin242):
Replying to [comment:3 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
--
Ticket URL: <https://code.djangoproject.com/ticket/26215#comment:4>
* Attachment "26215-test2.diff" added.
* Attachment "26215-test2.diff" added.
* needs_better_patch: 0 => 1
* component: Database layer (models, ORM) => contrib.postgres
* has_patch: 0 => 1
* stage: Unreviewed => Accepted
Old description:
> 1. FloatRangeField db data == None
> 2. ./manage dumpdata
> 3. ./manage loaddata
>
> Conversion problem. accept string u'None' to float type
>
> Track:
> 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>
> }}}
New description:
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>
}}}
--
Comment:
I've understood the problem now and attached a test. Not sure if the
proposed fix is correct.
--
Ticket URL: <https://code.djangoproject.com/ticket/26215#comment:5>
* needs_better_patch: 1 => 0
Comment:
On [https://github.com/django/django/pull/6145 that PR], I fixed the
problem by changing the serialization in the first place (outputting
`null` instead of `'None'` from `RangeField.value_to_string`).
--
Ticket URL: <https://code.djangoproject.com/ticket/26215#comment:6>
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/26215#comment:7>
Comment (by claudep):
For the records, this might be a regression introduced by #24937.
--
Ticket URL: <https://code.djangoproject.com/ticket/26215#comment:8>
* status: new => closed
* resolution: => fixed
Comment:
In [changeset:"928c12eb1a75dbcab22b64f8cf0afb17389c20d2" 928c12e]:
{{{
#!CommitTicketReference repository=""
revision="928c12eb1a75dbcab22b64f8cf0afb17389c20d2"
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.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/26215#comment:9>
Comment (by Claude Paroz <claude@…>):
In [changeset:"205cafd01ebe0f1c72ef3772a1b3f195387f4c50" 205cafd0]:
{{{
#!CommitTicketReference repository=""
revision="205cafd01ebe0f1c72ef3772a1b3f195387f4c50"
[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.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/26215#comment:10>
Comment (by Claude Paroz <claude@…>):
In [changeset:"5bce6659741ff8cf08a28f0e7fb05783c6fcf5d4" 5bce6659]:
{{{
#!CommitTicketReference repository=""
revision="5bce6659741ff8cf08a28f0e7fb05783c6fcf5d4"
[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.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/26215#comment:11>