Opened 17 years ago

Closed 17 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: dev
Severity: 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

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.

Change History (1)

comment:1 by Malcolm Tredinnick, 17 years ago

Resolution: invalid
Status: newclosed

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).

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