non-CRUD form creation Error

54 views
Skip to first unread message

Alan Etkin

unread,
Oct 7, 2025, 7:47:33 PM (12 days ago) Oct 7
to py4web
Hello again!

I'm facing an issue whith the example of non-CRUD forms in docs. Doesn't look like an error in the logic of the controller. The code is based in the example posted here

What I'm trying to do is tho create a custom form (non-crud) with some fields.

@action("carga_combinada")
@action.uses("generic.html", flash)
def carga_combinada():
    # declaro los ROLES para poder usarlos en el formulario non-CRUD
    ROLES = ["DBA", "Analista", "Diseñador", "Front end", "Programador"]
    fields = [Field("nombre"),
              Field("rol", requires=IS_IN_SET(ROLES)),
              Field("descripcion",
                    requires=IS_NOT_EMPTY(error_message="¡Epa! Te olvidaste de completar qué se va a hacer"),
                    label="Descripción"),
              Field("inicio", "datetime"),
              Field("estimacion", "integer",
                    label="Estimación",
                    comment = "Duración estimada de la tarea en horas")]
    form = Form(fields)
    if form.accepted:
        flash.set("La información se cargó correctamente")
        redirect(URL("index"))
    return locals()

When I load the action with a development server, it raises an error with this traceback.

Traceback (most recent call last): File "/home/alan/py4web_venv/lib/python3.12/site-packages/py4web/core.py", line 1059, in wrapper ret = func(*func_args, **func_kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/alan/py4web_venv/lib/python3.12/site-packages/py4web/core.py", line 1044, in wrapper raise exception File "/home/alan/py4web_venv/lib/python3.12/site-packages/py4web/core.py", line 1037, in wrapper call_f(fixture.on_success, context) File "/home/alan/py4web_venv/lib/python3.12/site-packages/py4web/core.py", line 1002, in call_f return f(context) ^^^^^^^^^^ File "/home/alan/py4web_venv/lib/python3.12/site-packages/py4web/core.py", line 626, in on_success context["output"] = render( ^^^^^^^ File "/home/alan/py4web_venv/lib/python3.12/site-packages/py4web/core.py", line 588, in render return engine.render(filename, context=context) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/alan/py4web_venv/lib/python3.12/site-packages/renoir/apis.py", line 172, in render return self._render(source, file_path, context) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/alan/py4web_venv/lib/python3.12/site-packages/renoir/apis.py", line 166, in _render make_traceback(exc_info) File "/home/alan/py4web_venv/lib/python3.12/site-packages/renoir/debug.py", line 114, in make_traceback reraise(exc_type, exc_value, tb) File "/home/alan/py4web_venv/lib/python3.12/site-packages/renoir/_internal.py", line 15, in reraise raise value.with_traceback(tb) File "/home/alan/Proyectos/py4web/apps/formularios/templates/generic.html", line 11, in template [[=BEAUTIFY(__vars__)]] File "/home/alan/py4web_venv/lib/python3.12/site-packages/yatl/helpers.py", line 583, in BEAUTIFY TBODY(*[TR(TH(key), TD(BEAUTIFY(value))) for key, value in obj.items()]) ^^^^^^^^^^^^^^^ File "/home/alan/py4web_venv/lib/python3.12/site-packages/yatl/helpers.py", line 580, in BEAUTIFY return UL(*[LI(BEAUTIFY(item)) for item in obj]) ^^^^^^^^^^^^^^ File "/home/alan/py4web_venv/lib/python3.12/site-packages/yatl/helpers.py", line 588, in BEAUTIFY return repr(obj) ^^^^^^^^^ File "/home/alan/py4web_venv/lib/python3.12/site-packages/pydal/objects.py", line 1676, in __repr__ return str(self.db._adapter.expand(self, self.type)) ^^^^^^^^^^^^^^^^ AttributeError: 'NoneType' object has no attribute '_adapter'

Added the complete controller code and the ticket report

Regards

Alan
f618f916-42ce-49b8-94c7-bdd757231132.html
controllers.py

Alan Etkin

unread,
Oct 7, 2025, 8:07:46 PM (11 days ago) Oct 7
to py4web
I've found a "workaround", bypassing the exception in __repr__ method from Expression class in pydal/objects.py

Regards

Alan Etkin

unread,
Oct 8, 2025, 6:12:14 PM (11 days ago) Oct 8
to py4web
The problem is related with passing Field instances as return value of the controller function. A way of avoiding this is to prevent those objects to be passed when the function returns 

Massimo DiPierro

unread,
Oct 12, 2025, 1:03:46 PM (7 days ago) Oct 12
to py4web
The problem is that it does not know how to repr(Field) if the Field is not linked to a table.
You can replace "return locals()" with "return dict(form=form)" so that you do not expose the list of fields. That is good practice anyway.
I will add a Field.__repr__ that works in every case.

Alan Etkin

unread,
Oct 16, 2025, 7:37:14 AM (3 days ago) Oct 16
to py4web
> You can replace "return locals()" with "return dict(form=form)" so that you do not expose the list of fields. That is good practice anyway.

Alright. The thing is that newcomers could by following the example try (as I did) to return a list of Field objects and the view processing does not know how to handle it. I think that this error might reproduce with other objects not supported by the repr method. Perhaps instead of supporting any object by __repr__ would be better to warn users in the docs.

Regards

Massimo DiPierro

unread,
Oct 16, 2025, 10:37:02 AM (3 days ago) Oct 16
to Alan Etkin, py4web
This has been fixed in the new pydal 

--
You received this message because you are subscribed to the Google Groups "py4web" group.
To unsubscribe from this group and stop receiving emails from it, send an email to py4web+un...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/py4web/a66e91e8-632f-4972-b0ec-cd805379c99dn%40googlegroups.com.

Alan Etkin

unread,
Oct 17, 2025, 10:47:53 AM (2 days ago) Oct 17
to py4web
Thanks Massimo!
Reply all
Reply to author
Forward
0 new messages