Expr statements do not use argument variables to load objects

Bug #798938 reported by Marc Tardif
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Storm
New
Undecided
Unassigned

Bug Description

First, consider this SQL column definition:

  date_created TIMESTAMP WITHOUT TIME ZONE

Second, consider this UTCDateTime property defined to set the timezone:

  class UTCDateTimeVariable(DateTimeVariable):
      def __init__(self, *args, **kwargs):
          kwargs["tzinfo"] = pytz.timezone("UTC")
          super(UTCDateTimeVariable, self).__init__(*args, **kwargs)
  class UTCDateTime(DateTime):
      variable_class = UTCDateTimeVariable

Third, consider this class definition referring to the above column definition and property:

  class Foo:
    date_created = UTCDateTime()

This works fine when getting an object directly from the store:

  foo = store.get(Foo, 1)
  print foo.date_created.tzinfo
  <UTC>

However, this doesn't work when using an expression referring to the column:

  max_date_created = store.find(Max(Foo.date_created)).get_one()
  print max_date_created.tzinfo
  None

The problem seems to be that Expr statements like Max don't look into their expression arguments to determine how the object should be loaded. Instead, in the case of the postgres backend, they rely solely on the loading performed by psycopg2. Since most use cases for statements like Max pass properties as arguments, it would probably be desirable to check the arguments for the most appropriate way to load the objects.

Marc Tardif (cr3)
description: updated
description: updated
Marc Tardif (cr3)
description: updated
description: updated
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.