Bug: Field.count() returning Expression of type Field.type instead of 'integer'?

14 views
Skip to first unread message

Osman Masood

unread,
Aug 15, 2012, 10:51:48 AM8/15/12
to
Hey guys,
Is there a reason why Field.count() now returns an Expression of type=self.type instead of 'integer'? It breaks code that uses datetime columns with count and groupby, like so:

db().select(db.tablename.addedTime, db.tablename.addedTime.count(), groupby=db.tablename.addedTime.month() | db.tablename.addedTime.year()).first()

(Gives a ValueError: need more than 1 value to unpack because, since the Expression is a 'datetime', it calls parse_datetime with an integer value.)

The patch is simple:
(Line 8311, latest version of trunk)
-        return Expression(self.db, self.db._adapter.COUNT, self, distinct, self.type)
+        return Expression(self.db, self.db._adapter.COUNT, self, distinct, 'integer')

If there's a reason why Field.count() returns Expression of type=self.type, let me know and I can make a workaround. By the way, the patch in which this was done is at: https://github.com/web2py/web2py/commit/15f3cdf888994da12ca95c26a8138b4a4b6b9e50#gluon/dal.py
Doesn't seem to be a reason why it was switched from self.type to integer.
Reply all
Reply to author
Forward
0 new messages