Code

Opened 6 years ago

Closed 6 years ago

#6152 closed (invalid)

django.db.models.Field.to_python not called by QuerySet

Reported by: Daniel Pope Owned by: nobody
Component: Database layer (models, ORM) Version: master
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

The to_python function is intended to convert a database representation to a Python object. In Django SVN this function is not called when Model instances are loaded. In built-in fields this omission no effect because the Python DB-API also has a mapping which, coincidentally, converts to the correct types.

However, for user-defined Fields, to_python must be called or the field is assigned the raw database type.

I wonder if the correct solution is to call obj.validate() (which calls to_python() for all fields) just before yielding the obj in QuerySet.__iter__. This, at least, is how I have patched my installation in order to make user-defined fields work as intended.

Attachments (0)

Change History (1)

comment:1 Changed 6 years ago by mtredinnick

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to invalid
  • Status changed from new to closed

There's no bug here. Your custom field subclass is required to handle this. See http://www.djangoproject.com/documentation/custom_model_fields/ for one easy way to do (custom_model_fields.txt in the source tree).

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.