IS_IN_DB(set, ...) validator doesn't work with GAE

31 views
Skip to first unread message

David Manns

unread,
Apr 22, 2016, 1:11:36 PM4/22/16
to web2py-users
I'm resubmitting as this has not been fixed. I understand the problem better and have a workaround.

My application runs on GAE and has been stuck on 2.9.12.

Runs fine in web2py test environment and with 2.9.12 (pre pyDAL)

In both production and SDK GAE various pages fail. 

This failure relates to using a set in a validator:

...
banks = db(db.CoA.Type == 'Bank')

form=SQLFORM.factory(
Field('bank', 'reference CoA', requires=IS_EMPTY_OR(IS_IN_DB(banks, 'CoA.id','%(Name)s'))),
...

In the model:


db.define_table('CoA',
Field('Type', 'string', default='Expense', requires = IS_IN_SET(['Bank', 'Asset/Liability', 'Revenue/Expense'])),
Field('Name', 'string', unique = True),
Field('Balance', 'decimal(9,2)'), #used to maintain PayPal and Bank balances
Field('Notes', 'text'),
format='%(Name)s')
db.CoA.Name.requires = [IS_NOT_EMPTY(), IS_NOT_IN_DB(db, 'CoA.Name')]

GAE SDK log error attached.

Note IS_IN_DB works fine with IS_IN_SET(db, ...) - I use it all over the place.

In validators.py line 584 is in an if...else construct that tries to check for 'gae'. This test is wrong, the adapter name would be 'google:datastore' which would run the else clause. I tried this and established that the else clause also fails. It looks to me as if this historical work around in validators.py is broken, quite apart from how to fix the test. Perhaps the implementation of 'set' can be changed to be agnostic?

The workaround for me was to use IS_IN_SET instead:

...
    banks = []
    coa = db(db.CoA.id > 0).select(orderby=db.CoA.Name)
    for c in coa:
        if c.Type == 'Bank':
            banks.append((c.id, c.Name))
...
    form=SQLFORM.factory(
        Field('bank', 'reference CoA', requires=IS_EMPTY_OR(IS_IN_SET(banks))),
...
error.txt

Niphlod

unread,
Apr 22, 2016, 2:27:15 PM4/22/16
to web2py-users
If I were you I'd log an issue over at pydal's repo. https://github.com/web2py/pydal/issues

David Manns

unread,
Apr 22, 2016, 4:26:22 PM4/22/16
to web...@googlegroups.com
Thanks, I added a comment to https://github.com/web2py/web2py/issues/902 which looks to be the same issue and is open.

--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/FoE02rb8LWU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages