Issue with pydal and non-database upload fields

65 views
Skip to first unread message

Jim Steil

unread,
Aug 1, 2022, 4:02:32 PM8/1/22
to py4web
I ran into an issue today with the lastest py4web/pydal and an upload field that is not tied to a database field.

I received this traceback when processing the form:

Traceback (most recent call last):
  File "/home/jim/dev/py4web/py4web/core.py", line 934, in wrapper
    ret = func(*func_args, **func_kwargs)
  File "/home/jim/dev/py4web/py4web/core.py", line 919, in wrapper
    raise context["exception"]
  File "/home/jim/dev/py4web/py4web/core.py", line 898, in wrapper
    context["output"] = func(*args, **kwargs)
  File "/home/jim/dev/py4web/apps/connect4/controllers/price_quote.py", line 661, in brill_import
    form = Form(
  File "/home/jim/dev/py4web/py4web/utils/form.py", line 830, in __init__
    value = field.store(
  File "/home/jim/.local/lib/python3.10/site-packages/pydal/objects.py", line 2072, in store
    uuid_key = self._db.uuid().replace("-", "")[-16:]
AttributeError: 'NoneType' object has no attribute 'uuid'

I traced it back to lines 2072 through 2079 of pydal

Originally it was:

        uuid_key = self._db.uuid().replace("-", "")[-16:] if self._db else uuidstr()
        encoded_filename = to_native(base64.urlsafe_b64encode(to_bytes(filename)))
        newfilename = "%s.%s.%s.%s" % (
            self._tablename if '_tablename' in self.__dir__() and self._tablename else 'no_table',
            self.name,
            uuid_key,
            encoded_filename,
        )

...which caused the error.

I changed it to:

        uuid_key = self._db.uuid().replace("-", "")[-16:] if self._db else uuidstr()
        encoded_filename = to_native(base64.urlsafe_b64encode(to_bytes(filename)))
        newfilename = "%s.%s.%s.%s" % (
            self._tablename if '_tablename' in self.__dir__() and self._tablename else 'no_table',
            self.name,
            uuid_key,
            encoded_filename,
        )

...and now it built the filename successfully.

Attached is a minimal app where you can see the issue.

The issue goes away with the provided fix.

I will report in pydal on github and submit a PR.

-Jim

upload_field.zip

CarlosDB

unread,
Aug 2, 2022, 12:41:39 PM8/2/22
to py4web
Related to this thread I started a few weeks ago.

Jim Steil

unread,
Aug 2, 2022, 2:26:32 PM8/2/22
to py4web
You are correct, I totally forgot about that.  I submitted a pydal PR.  Let's see what Massimo decides to do with that.

-Jim

Jim Steil

unread,
Aug 7, 2022, 8:48:29 PM8/7/22
to py4web
Massimo updated pydal in pypi to a new version today that should address this issue.

-Jim
Reply all
Reply to author
Forward
0 new messages