Closed keredson closed 7 years ago
break occurred upstream between 2.8.3 and 2.8.4. 2.8.4 changelog mentions:
As a miscellaneous note, I did some major refactoring and cleanup in ExtQueryResultsWrapper and it's corollary in the speedups module. The code is much easier to read than before.
isolated test case:
import logging, os, sys
import peewee as pw
logger = logging.getLogger('peewee')
logger.setLevel(logging.DEBUG)
logger.addHandler(logging.StreamHandler())
os.system('dropdb test3')
os.system('createdb test3')
db = pw.PostgresqlDatabase('test3')
class Page(pw.Model):
name = pw.CharField(default='Page')
class Meta:
database = db
class PageVisit(pw.Model):
page = pw.ForeignKeyField(rel_model=Page)
class Meta:
database = db
db.create_tables([Page, PageVisit])
page = Page.create()
PageVisit.create(page=page)
PageVisit.create(page=page)
print list(PageVisit.select(PageVisit.page, pw.fn.Count(PageVisit.page)).group_by(PageVisit.page).dicts())
so the root is this rewrite of ExtQueryResultsWrapper.
specifically this line:
self.column_names.append(node._alias or arg._alias or arg.name)
in the previous version of this class, it used the name of the column returned by the database (count
in our case) as the name. in this version, if the function doesn't have an alias, it uses the name of the first argument in the function.
in addition to breaking backward compat, this seems really wrong and highly likely to result in collisions. we often do queries like select fk_id, count(fk_id) from xxx group by fk_id
that would break by this. but what should the behavior be? (i could see an argument for this too, if my function is LOWERCASE()
or something, but it still seems surprising.)
i don't like the original behavior either. the resultant dict should not be database dependent. (postgres returns count
, but mysql returns the full function def.) so i think i'm settling on it should just return the function name. (not the arg name) plus that's a low impact change.
open to other opinions tho.
example:
now returns:
note the lack of a
count
field. same if you look at the model, etc...@brenguyen711
edit the count field is not missing, the
2L
is the count, but w/ the wrong key. the page id is actually what is missing.