On Wed, Jan 7, 2009 at 7:46 AM, Russell Keith-Magee
<freakboy3...@gmail.com> wrote:
> There is some potential for further refactoring here, especially with
> regards to the decimal/datetime conversion routines. The Oracle
> DatabaseOperations.convert_values() function that I added for
> aggregate support is an almost perfect subset of the features in the
> Oracle Query.convert_values() function.
>
> Refactoring Query.convert_values() into the backend operations would
> remove some code duplication, and would also serve to keep all the
> data coercion/typecasting code in a common location rather than
> spreading some of it into the Query class. However, there are two
> things that prevented me from doing this refactor.
>
> Firstly, Query.convert_values() uses a lot of isinstance() calls on
> fields, rather than checking the internal type of the field.
> Aggregates use the internal type because aggregates aren't actually
> fields, but they do return database types. Ian - can you see a problem
> with converting the isinstance(field, DecimalField) calls to
> field.get_internal_type() == 'DecimalField' etc?

Yes - field could be None, resulting in an AttributeError.  I see no
problem replacing them with (field and field.get_internal_type() ==
'DecimalField').

Currently we seem to be calling convert_values twice for each
aggregate value of an annotate query.  First, query.convert_values
gets called from resolve_columns with a None field.  Later,
ops.convert_values gets called with the actual field.  The reason I
bring this up is that the former call might interfere with the latter
call.  For example, if an aggregate value of a DateTimeField has a
time component of exactly midnight, the former call will incorrectly
assume it's meant to be a date value and cast it as such.  The latter
call would then need to be intelligent enough to reverse it.  In
refactoring these methods, would it be an extraordinary effort to also
refactor the calls so that the former call never happens?

Ian

--~--~---------~--~----~------------~-------~--~----~
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 
django-developers+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to