Form record id sometimes balks

38 views
Skip to first unread message

ppage...@gmail.com

unread,
Apr 15, 2020, 7:13:34 PM4/15/20
to py4web
I really don't understand this. When I put the following controller into examples/controller.py, it works.

@action("update_form2", method=["GET", "POST"])
@action.uses("form.html", db, session, T)
def update_form2():
    form=None
    if ('table_name' in request.query) and ('key_id' in request.query):
        t = request.query.get('table_name')
        k = request.query.get('key_id')
        print(t, k)#-->prints correct output
        form = Form(db[t], k, deletable=False, formstyle=FormStyleBulma) # <--- This fails
        rows = db(db[t].id==k).select()# <--- This works fine
    else:
        return dict(rows=None, form=None, title='error in URL request object')
    return dict(form=form, rows=rows, title='Form for Table {} Row {}'.format(t,k))

If I put the same controller in my app (which has a different db), it does not work. Except when key_id or k is None. I can delete the rest of my controllers, I can swap all the imports, it still doesn't work. And, at least to my eye, the error is not particularly informative. I get the same error whether the url is request object as here or app/update_form2/k (where I hard code the table_name). Also, the select which populates rows works just fine. 

ERROR:root:Traceback (most recent call last):

  File "/Users/webapps/Documents/WebApps/py4web/py4web/core.py", line 580, in wrapper

    ret = func(*func_args, **func_kwargs)

  File "/Users/webapps/Documents/WebApps/py4web/py4web/core.py", line 540, in wrapper

    ret = func(*args, **kwargs)

  File "/Users/webapps/Documents/WebApps/py4web/apps/Cage/controllers.py", line 155, in update_form2

    form = Form(db[t], k, deletable=False, formstyle=FormStyleBulma)

  File "/Users/webapps/Documents/WebApps/py4web/py4web/utils/form.py", line 227, in __init__

    self._read_vars_from_record(table)

  File "/Users/webapps/Documents/WebApps/py4web/py4web/utils/form.py", line 278, in _read_vars_from_record

    for name in table.fields

  File "/Users/webapps/Documents/WebApps/py4web/py4web/utils/form.py", line 279, in <dictcomp>

    if name in self.record

  File "/Users/webapps/Library/Python/3.7/lib/python/site-packages/pydal/objects.py", line 2161, in formatter

    value = item.formatter(value)

  File "/Users/webapps/Library/Python/3.7/lib/python/site-packages/pydal/validators.py", line 3725, in formatter

    format = format.replace("%y", y[-2:])

AttributeError: 'lazyT' object has no attribute 'replace'


I suspect the problem is in __init__ of form.py. Here?


        if readonly or request.method == "GET":

            self._read_vars_from_record(table)

        else:...

I assume somehow in one context I am readonly==True, and the other I pass that if. I can't find where readonly would have been set, in my App anyway.


Thoughts? Really enjoying playing (very ineptly) with py4web.

Patrick

Reply all
Reply to author
Forward
0 new messages