Aggregates of allow_none=False columns break for empty result sets

Bug #457801 reported by James Henstridge on 2009-10-22
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Storm
Medium
James Henstridge

Bug Description

Aggregates return NULL if they are applied to an empty result set.

The ResultSet aggregate code tries to convert the return value to the same variable type as used by the column being aggregated. If that column uses allow_none=False and the result set in question is empty then this conversion results in a NoneError.

Test code:
    from storm.locals import *

    class Foo(object):
        __storm_table__ = "foo"
        id = Int(primary=True)
        number = Int(allow_none=False)

    store = Store(create_database("sqlite:"))
    store.execute(
        "CREATE TABLE foo (id INTEGER PRIMARY KEY, number INTEGER NOT NULL)")
    result = store.find(Foo)
    print result.max(Foo.number)

Failure:
    Traceback (most recent call last):
      File "breakme.py", line 13, in <module>
        print result.max(Foo.number)
      File "storm/store.py", line 1220, in max
        return self._aggregate(Max, expr, expr)
      File "storm/store.py", line 1210, in _aggregate
        result.set_variable(variable, value)
      File "storm/databases/sqlite.py", line 83, in set_variable
        variable.set(value, from_db=True)
      File "storm/variables.py", line 217, in set
        raise_none_error(self.column)
      File "storm/variables.py", line 72, in raise_none_error
        raise NoneError("None isn't acceptable as a value for %s" % name)
    storm.exceptions.NoneError: None isn't acceptable as a value for foo.number

Related branches

Changed in storm:
milestone: none → 0.16
assignee: nobody → James Henstridge (jamesh)
status: New → In Progress
importance: Undecided → Medium
James Henstridge (jamesh) wrote :

Fix merged to trunk in r336.

Changed in storm:
status: In Progress → Fix Committed
Jamu Kakar (jkakar) on 2009-11-29
Changed in storm:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers