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