I believe this is a known bug. Common fields are ignored if there i no query. Please check if
db().select(db.p2.name) and db(db.p2).select(db.p2.name) give different results. I believe there is an open ticket about this. I will try fix it asap. On Sunday, 25 November 2012 16:00:02 UTC-6, Brian Zhou wrote: > > #!/usr/bin/env python > > # export PYTHONPATH=.../web2py > > from gluon import DAL, Field > > def def_tables(db): > > p2 = db.define_table('p2', > Field('name', 'string'), > Field('is_active', 'boolean', default=True), > common_filter = lambda q: db.p2.is_active==True) > > def get_db(): > return DAL('sqlite://storage.sqlite') > > def get_db_with_schema(): > db = get_db() > def_tables(db) > return db > > def db_ops(db): > db.p2.truncate() > > db.p2.insert(name='Alice') > db.p2.insert(name='Bob') > db.commit() > > print 'before deactivating Alice' > print db(db.p2.name=='Alice').update(is_active=False) > print 'after deactivating Alice' > db.commit() > > def test(): > db = get_db_with_schema() > db_ops(db) > print db.p2._common_filter > print 1, [r.name for r in db().select(db.p2.name)] > print 2, [r.name for r in db(ignore_common_filters=False).select( > db.p2.name)] > print 3, [r.name for r in db(ignore_common_filters=True).select( > db.p2.name)] > print 4, [r.name for r in db(db.p2.is_active==True).select(db.p2.name > )] > > if __name__ == "__main__": > test() > > $ sqlite3 -column -header storage.sqlite 'select * from p2;' > id name description is_active > ---------- ---------- ----------- ---------- > 1 Alice F > 2 Bob T > > $ python test_common_filter.py # against git main branch 1b0e08 > before deactivating Alice > 1 > after deactivating Alice > <function <lambda> at 0x2aca500> > 1 ['Alice', 'Bob'] > 2 ['Alice', 'Bob'] > 3 ['Alice', 'Bob'] > 4 ['Bob'] > > This is as if common_filter has no effect at all. I was expecting to see > 1 ['Bob'] > 2 ['Bob'] > 3 ['Alice', 'Bob'] > 4 ['Bob'] > > Did I miss something? Or is this a bug? > > Thanks! > > -Brian > --