Code

Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#2893 closed defect (duplicate)

IntegerField (and subclasses), FloatField lack to_python method

Reported by: andrew@… Owned by: adrian
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: UI/UX:

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

Attachments (0)

Change History (1)

comment:1 Changed 8 years ago by andrew@…

  • Resolution set to duplicate
  • Status changed from new to closed

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)

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.