[Django] #26215: if dumpdata FloatRangeField and IntegerRangeField values = "None" and post loaddata is ValidationError

18 views
Skip to first unread message

Django

unread,
Feb 12, 2016, 6:39:35 AM2/12/16
to django-...@googlegroups.com
#26215: if dumpdata FloatRangeField and IntegerRangeField values = "None" and post
loaddata is ValidationError
----------------------------------------------+--------------------
Reporter: bukin242 | Owner: nobody
Type: Bug | Status: new
Component: Database layer (models, ORM) | Version: 1.9
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------------------+--------------------
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 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.

Django

unread,
Feb 12, 2016, 6:43:01 AM2/12/16
to django-...@googlegroups.com
#26215: if dumpdata FloatRangeField and IntegerRangeField values = "None" and post
loaddata is ValidationError
-------------------------------------+-------------------------------------

Reporter: bukin242 | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.9
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by bukin242):

* 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>

Django

unread,
Feb 12, 2016, 10:13:47 AM2/12/16
to django-...@googlegroups.com
#26215: if dumpdata FloatRangeField and IntegerRangeField values = "None" and post
loaddata is ValidationError
-------------------------------------+-------------------------------------

Reporter: bukin242 | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.9
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by bukin242):

* cc: bukin242 (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/26215#comment:2>

Django

unread,
Feb 12, 2016, 2:10:43 PM2/12/16
to django-...@googlegroups.com
#26215: if dumpdata FloatRangeField and IntegerRangeField values = "None" and post
loaddata is ValidationError
-------------------------------------+-------------------------------------

Reporter: bukin242 | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.9
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* Attachment "26215-test.diff" added.

Django

unread,
Feb 12, 2016, 2:10:53 PM2/12/16
to django-...@googlegroups.com
#26215: if dumpdata FloatRangeField and IntegerRangeField values = "None" and post
loaddata is ValidationError
-------------------------------------+-------------------------------------

Reporter: bukin242 | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.9
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

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>

Django

unread,
Feb 13, 2016, 11:11:33 AM2/13/16
to django-...@googlegroups.com
#26215: if dumpdata FloatRangeField and IntegerRangeField values = "None" and post
loaddata is ValidationError
-------------------------------------+-------------------------------------

Reporter: bukin242 | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.9
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

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>

Django

unread,
Feb 15, 2016, 12:22:07 PM2/15/16
to django-...@googlegroups.com
#26215: if dumpdata FloatRangeField and IntegerRangeField values = "None" and post
loaddata is ValidationError
-------------------------------------+-------------------------------------

Reporter: bukin242 | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.9
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* Attachment "26215-test2.diff" added.

Django

unread,
Feb 15, 2016, 12:22:41 PM2/15/16
to django-...@googlegroups.com
#26215: if dumpdata FloatRangeField and IntegerRangeField values = "None" and post
loaddata is ValidationError
-------------------------------------+-------------------------------------

Reporter: bukin242 | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.9
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* Attachment "26215-test2.diff" added.


Django

unread,
Feb 15, 2016, 12:25:56 PM2/15/16
to django-...@googlegroups.com
#26215: FloatRangeField/IntegerRangeField with None as a range boundary doesn't
round trip in serialization
----------------------------------+------------------------------------

Reporter: bukin242 | Owner: nobody
Type: Bug | Status: new
Component: contrib.postgres | Version: 1.9
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
----------------------------------+------------------------------------
Changes (by timgraham):

* 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>

Django

unread,
Feb 15, 2016, 1:37:54 PM2/15/16
to django-...@googlegroups.com
#26215: FloatRangeField/IntegerRangeField with None as a range boundary doesn't
round trip in serialization
----------------------------------+------------------------------------
Reporter: bukin242 | Owner: nobody
Type: Bug | Status: new
Component: contrib.postgres | Version: 1.9
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
----------------------------------+------------------------------------
Changes (by claudep):

* 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>

Django

unread,
Feb 15, 2016, 2:22:50 PM2/15/16
to django-...@googlegroups.com
#26215: FloatRangeField/IntegerRangeField with None as a range boundary doesn't
round trip in serialization
-------------------------------------+-------------------------------------

Reporter: bukin242 | Owner: nobody
Type: Bug | Status: new
Component: contrib.postgres | Version: 1.9
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/26215#comment:7>

Django

unread,
Feb 15, 2016, 3:16:52 PM2/15/16
to django-...@googlegroups.com
#26215: FloatRangeField/IntegerRangeField with None as a range boundary doesn't
round trip in serialization
-------------------------------------+-------------------------------------
Reporter: bukin242 | Owner: nobody
Type: Bug | Status: new
Component: contrib.postgres | Version: 1.9
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by claudep):

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

--
Ticket URL: <https://code.djangoproject.com/ticket/26215#comment:8>

Django

unread,
Feb 16, 2016, 3:08:59 PM2/16/16
to django-...@googlegroups.com
#26215: FloatRangeField/IntegerRangeField with None as a range boundary doesn't
round trip in serialization
-------------------------------------+-------------------------------------
Reporter: bukin242 | Owner: nobody
Type: Bug | Status: closed
Component: contrib.postgres | Version: 1.9
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Claude Paroz <claude@…>):

* 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>

Django

unread,
Feb 16, 2016, 3:09:48 PM2/16/16
to django-...@googlegroups.com
#26215: FloatRangeField/IntegerRangeField with None as a range boundary doesn't
round trip in serialization
-------------------------------------+-------------------------------------
Reporter: bukin242 | Owner: nobody

Type: Bug | Status: closed
Component: contrib.postgres | Version: 1.9
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

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>

Django

unread,
Feb 16, 2016, 3:16:16 PM2/16/16
to django-...@googlegroups.com
#26215: FloatRangeField/IntegerRangeField with None as a range boundary doesn't
round trip in serialization
-------------------------------------+-------------------------------------
Reporter: bukin242 | Owner: nobody

Type: Bug | Status: closed
Component: contrib.postgres | Version: 1.9
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

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>

Reply all
Reply to author
Forward
0 new messages