Opened 18 years ago

Closed 18 years ago

Last modified 18 years ago

#2893 closed defect (duplicate)

IntegerField (and subclasses), FloatField lack to_python method

Reported by: andrew@… Owned by: Adrian Holovaty
Component: Core (Other) Version:
Severity: normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

IntegerField (in django.db.models.fields) and FloatField subclass Field but do not define a to_python method. They inherit Field's simple 'return value' to_value implementation.

This can be a problem when using Django's XML serializer and deserializer together. Since the deserializer passes in a string representation of the value to to_python, a string representation of the value is written to the object. This can make string formatting (%d, %f) and presumably other code unhappy. I suspect that this may not cause a problem in all cases. If an error is not triggered, it may be possible for the values to be saved to the database without incident, thereby allowing future retrievals to have the appropriate types.

AutoField provides an implementation of to_python which seems appropriate to copy-and-paste into place for IntegerField. The positive integer variants may benefit from bounds checking. FloatField would need logic along similar lines

Change History (1)

comment:1 by andrew@…, 18 years ago

Resolution: duplicate
Status: newclosed

Duplicate of #1553; regrettably missed that one in the search results, possibly because it was so old. (The problem and proposed fix are a subset of #1553)

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