Cannot check boolean field

29 views
Skip to first unread message

Ruud Schroen

unread,
Mar 28, 2015, 12:14:44 PM3/28/15
to web...@googlegroups.com
Hi,

I have the following model:

#Abstract category model, has references from multiple translations
db.define_table('pitch_category')  #No fields except for ID

#The category translations
db.define_table('pitch_category_translation',
   
Field('pitch_category', db.pitch_category, requires=IS_IN_DB(db,db.pitch_category.id,lambda r: get_default_translation(r.id)), label=T('Category')),
   
Field('lang', 'string', requires=IS_IN_SET(settings.languages), label=T('Language')),
   
Field('val', 'string', label=T('The translation')),
   
Field('is_default', 'boolean', label=T(
'This is the default translation. NOTE: there should be only one per category!'))
)

When i try to check if is_default is True, i get the following error:

<class 'gluon.contrib.pg8000.ProgrammingError'>(('ERROR', '42804', 'argument of IS TRUE must be type boolean, not type character'))

This is my SQL statement:
sql = """
SELECT
    p.ID,
    tr.val,
    def.val
  FROM pitch_category p
  LEFT OUTER JOIN pitch_category_translation tr
    ON p.ID = tr.pitch_category AND tr.lang = '%s'
  LEFT OUTER JOIN pitch_category_translation def
    ON p.ID = def.pitch_category AND def.is_default IS TRUE;
""" % language

Everything works, except for the boolean check...

Anthony

unread,
Mar 28, 2015, 1:56:03 PM3/28/15
to web...@googlegroups.com
In many of the adapters, web2py converts booleans to and from strings with values "T" and "F". So, depending on the adapter, if you are writing SQL manually, you may need to use those values instead of True and False.

Anthony
Reply all
Reply to author
Forward
0 new messages