Code

Opened 6 years ago

Closed 6 years ago

Last modified 3 years ago

#8298 closed (fixed)

Missing to_python methods causing issues with serialization

Reported by: andrewbadr Owned by: nobody
Component: Uncategorized Version: master
Severity: Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

Lack of to_python on IntegerField? is breaking our tests that read from XML fixtures.

From what I can tell, this how things are supposed to work: (1) an IntegerField is read in as unicode (from the XML fixture), (2) the row is saved to the database, and (3) field is an integer on the next read from db. However, on one model, we have a post-save signal handler that expects the field to be an integer. This handler throws an exception when it gets unicode, so our tests break.

Is accepting strings a part of the database interface definition? I'm guessing we'd hit this same problem if using a form.

Attachments (0)

Change History (4)

comment:1 Changed 6 years ago by mtredinnick

  • milestone set to 1.0 maybe
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

The database backends only know about "%s" format markers, so integers and strings are treated similarly at that low-level. Thus, models can happily have strings assigned to integer fields and they'll be stored correctly.

However, I suspect we should be storing proper integers when we can, in the light of no model-aware cleaning and validation in 1.0. Since to_python() is only called at save time, it's not that costly. I'm +0 on considering this a bug, but it's borderline as to the priority. Making 1.0-maybe for that reason.

comment:2 Changed 6 years ago by jacob

  • milestone changed from 1.0 maybe to 1.0

comment:3 Changed 6 years ago by russellm

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

(In [8515]) Fixed #8298: Added a to_python method for integer fields. This ensures that the data from deserialized instances is of correct type prior to saving. Thanks to Andrew Badr for the report.

comment:4 Changed 3 years ago by jacob

  • milestone 1.0 deleted

Milestone 1.0 deleted

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.