django.db.models.Field.to_python not called by QuerySet
|Reported by:||Daniel Pope||Owned by:||nobody|
|Component:||Database layer (models, ORM)||Version:||master|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
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.