random lambda error

56 views
Skip to first unread message

Júlia Rizza

unread,
Jul 9, 2014, 8:11:25 PM7/9/14
to web...@googlegroups.com
Hello,

I have an app runing in production on Apache and sometimes when navigating over it I receive a ticket with a lambda error. It happens ramdomly in a way that I wasn't able to predict what was causing it: already ocurred in a function called dashboard, in another called invite and some others. But the fact is that I do not call lambda in none of them. I only use lambda two times:

models/validators.py
db.board.slug.compute = lambda row: IS_SLUG()(row.title)[0]

controllers/painel.py | function: board()
try:
    int(request.args(1))
    user = db(db.auth_user.username == request.args(0)).select().first()
    board = db((db.board.created_by == user.id)&(db.board.id == request.args(1))).select().first()
except ValueError:
    user = db(db.auth_user.username == request.args(0)).select().first()
    board = db((db.board.created_by == user.id)&(db.board.slug == request.args(1))).select().first()
except TypeError:
    raise HTTP(404, T('No board specified!'))

text_type = db(db.text_type.board == board.id).select()
url_type = db(db.url_type.board == board.id).select()
image_type = db(db.image_type.board == board.id).select()
video_type = db(db.video_type.board == board.id).select()

merged_records = itertools.chain(text_type, url_type, image_type, video_type)
contents = sorted(merged_records, key=lambda record: record['topic_position'])

The ticket traceback is:

<type 'exceptions.TypeError'> <lambda>() takes no arguments (1 given)

1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
Traceback (most recent call last):
File "/home/www-data/web2py/gluon/restricted.py", line 217, in restricted
exec ccode in environment
File "/home/www-data/web2py/applications/cachola/controllers/painel.py", line 519, in <module>
File "/home/www-data/web2py/gluon/globals.py", line 372, in <lambda>
self._caller = lambda f: f()
File "/home/www-data/web2py/gluon/tools.py", line 3229, in f
'?_next=' + urllib.quote(next))
File "/home/www-data/web2py/gluon/tools.py", line 91, in call_or_redirect
redirect(f(*args))
TypeError: <lambda>() takes no arguments (1 given)

Can somebody help me to understand where is the problem?

Anthony

unread,
Jul 9, 2014, 8:31:19 PM7/9/14
to web...@googlegroups.com
Did you change auth.settings.on_failed_authentication from its default value?

Anthony

unread,
Jul 9, 2014, 8:33:12 PM7/9/14
to web...@googlegroups.com
Also, what version of web2py?

Júlia Rizza

unread,
Jul 9, 2014, 9:31:17 PM7/9/14
to web...@googlegroups.com
I've completely forgot about the on_failed_authentication, sorry.

models/db.py
auth.settings.on_failed_authentication = lambda: redirect(URL('painel', 'index'))

(web2py version 2.8.2-stable)

Anthony

unread,
Jul 9, 2014, 11:58:22 PM7/9/14
to web...@googlegroups.com
If you just want to specify a URL for redirect, you can do so without the lambda:

auth.settings.on_failed_authentication = URL('painel', 'index')

However, if you do define a lambda (or any callable), it should accept an argument.

Anthony

Júlia Rizza

unread,
Jul 10, 2014, 5:32:39 PM7/10/14
to web...@googlegroups.com
I misunderstood it, but it's clear now. Thank you Anthony!
Reply all
Reply to author
Forward
0 new messages