Hi all,

I had submitted a patch recently (#3982) that forces Django to use the
to_python method of individual fields when retrieving objects from a
database. I'm not being impatient, but I'd like to get some additional
feedback on this, in case I'm going about it all wrong, or if I'm
missing something important.

While I haven't traced through all the backend database driver code,
Django's lack of to_python references leads me to believe that type
coercion is handled entirely through the database driver. This works
well for most data types, as there's a clear conversion between SQL
data types and those of Python.

However, the problem comes in patches like #2443, where a new field
type uses SQL and Python data types that don't have an appropriate
implicit correlation. In that example, the field uses FloatField for
its get_internal_type (for compatibility with all backends), but
returns a native Python type of timedelta. Current code results in the
field being coerced solely by its SQL data type, even though it
defines its own to_python which would create a proper object.

My main questions are these:

* Am I right in thinking that Django's to_python method should be used
for type coercion, rather than relying solely on backend drivers?
* Are there other situations than database access where this type of
coercion might not be happening correctly?
* Are there other code locations that would need to be updated to use
this functionality?
* Are there deficiencies in the to_python methods of existing fields
that are preventing us from using them?

As a temporary solution, the validate method of Django models does use
to_python as part of its validation, and thus coerces the proper field
types. However, it seems silly to require developers to use
object.validate() immediately after loading an object from the
database (before any modifications are made), just to get proper data
types.

Thoughts?

-Gul


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to django-developers@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to