mysql: grid fails trying to get Field.type_name attr

23 views
Skip to first unread message

Alan Etkin

unread,
Mar 8, 2026, 12:20:16 PMMar 8
to py4web
Hi, I found wat looks like a bug about Grid and DAL pymysql connections. Here is the error traceback:

Traceback (most recent call last): File "/home/alanetkinet29/py4web/py4web/core.py", line 1061, in wrapper ret = func(*func_args, **func_kwargs) File "/home/alanetkinet29/py4web/py4web/core.py", line 1046, in wrapper raise exception File "/home/alanetkinet29/py4web/py4web/core.py", line 1022, in wrapper context["output"] = func(*args, **kwargs) ~~~~^^^^^^^^^^^^^^^^^ File "/home/alanetkinet29/py4web/apps/proyectero/controllers.py", line 384, in tasks grid = Grid(query=db.task.stage.belongs(stage_list), columns=columns, create=is_admin, editable=is_admin, deletable=is_admin) File "/home/alanetkinet29/py4web/py4web/utils/grid.py", line 572, in __init__ self.process() ~~~~~~~~~~~~^^ File "/home/alanetkinet29/py4web/py4web/utils/grid.py", line 645, in process self._handle_mode_select() ~~~~~~~~~~~~~~~~~~~~~~~~^^ File "/home/alanetkinet29/py4web/py4web/utils/grid.py", line 781, in _handle_mode_select col.type_name AttributeError: 'Field' object has no attribute 'type_name'

The app was delployed in Pythonanywhere with the recipe from the docs
The same error with last py4web git version and using version 1.20251212.1

It looks like the Field objects from the mysql connection do not implement a .type_name attribute where with other dal adapters they do (i.e. SQLlite). Patching grid.py 781 to use .type instead of .type_name changes grid behavior since list types are rendered as python lists.

I'm using pymysql, perhaps I should change the mysql adapter?

Regards

Alan

Ali

unread,
Mar 8, 2026, 12:51:13 PMMar 8
to py4web
Hi Alan,

Just in case, I share my experience.

I have been able to successfully deploy to AWS RDS MySQL. Below are my settings:

settings.py:

run_on_cloud = True
if run_on_cloud:
    if database_type == "AWS RDS MySQL":
        cloud_database_string = "mysql://{DB_USER}:{DB_PASSWORD}@{DB_CONNECTION}:3306/{DB_NAME}?set_encoding=utf8mb4"

    elif database_type == "GAE":
        cloud_database_string = "google:MySQLdb://{DB_USER}:{DB_PASSWORD}@/{DB_NAME}?unix_socket=/cloudsql/{DB_CONNECTION}"

    CLOUD_DB_URI = cloud_database_string.format(
        DB_USER=DB_USER,
        DB_NAME=DB_NAME,
        DB_PASSWORD=DB_PASSWORD,
        DB_CONNECTION=DB_CONNECTION)

    CLOUD_DB_POOL_SIZE = 1
    CLOUD_DB_MIGRATE = False  # Temoporarily switch to True whenever a table is added or updated!
    CLOUD_DB_FAKE_MIGRATE = False


common.py

if settings.run_on_cloud:
    if settings.database_type == "AWS RDS MySQL":
        import pymysql

    db = DAL(
        settings.CLOUD_DB_URI,
        migrate=settings.CLOUD_DB_MIGRATE,
        fake_migrate=settings.CLOUD_DB_FAKE_MIGRATE,
    )

One last point, AWS is expiring RDS MySQL databases later this year. But I hope the settings provided above continue to work on whatever replacement they are going to use.

- ali

Alan Etkin

unread,
Mar 8, 2026, 1:56:20 PMMar 8
to py4web
Hi Ali, thanks for the feedback. I'm using these migrate settings:

DB_MIGRATE = True
DB_FAKE_MIGRATE = False

Which come by default in the settings scaffolding module.

I don't think it is about a connection issue as the connection object is created without errors. I tested the app in a local machine with very similar environment as Pythonanywhere's, and the Grid works like a charm! So, turns out that doesn't seem to be a Grid/py4web issue about mysql connections. Still, the type_name attributes of field objects at Pythonanywhere deploy are missing

Regards

Alan Etkin

unread,
Mar 8, 2026, 3:00:08 PMMar 8
to py4web
Checking deploy and local envs with _dashboard sys I've found that Pythonanywhere runs an older pydal version (20250607.2), while at local machine it is using 20260110.1 maybe I can update pydal on deployment and workaround the issue.
Reply all
Reply to author
Forward
0 new messages