A problem with Pydal 20250623.1

72 views
Skip to first unread message

David Manns

unread,
Aug 9, 2025, 11:38:04 AMAug 9
to py4web
I have grids where a column displays a reference to another table. With Pydal through 20250607.2 the column correctly displays using the referenced table's format=....

With the latest Pydal, the raw record id in the referenced table is displayed?

David Manns

unread,
Aug 10, 2025, 2:08:43 PMAug 10
to py4web
The problem is still there in 20250629.2

Massimo DiPierro

unread,
Sep 1, 2025, 2:07:10 PM (6 days ago) Sep 1
to py4web
I think I have a solution in master to this problem. Making formatters_by_type always overule table.field.represent for automatic columns. That means you can change the behavior per column using Grid([Column(db.table.field, represent=db.table.field.represent),..]) to force it to not override.
No solution is perfect here but I think it makes sense that db.table.field.represent is a default that grid overrides either per type or per column.
If not objections and if this restores the behavior you expect I will release a new version with this change.

Massimo

David Manns

unread,
Sep 1, 2025, 3:00:32 PM (6 days ago) Sep 1
to py4web
Your change is no doubt valid, but it doesn't address my actual problem. I have tables:

db.define_table('Colleges', #contains the individual colleges and other Oxbridge institutions, plus
Field('Name', 'string'), #organizations with whom we co-sponsor events.
...
format='%(Name)s')


db.define_table('Members',
Field('Firstname', 'string', requires = [IS_NOT_EMPTY(), CLEANUP()], comment='*'),
Field('Lastname', 'string', requires = [IS_NOT_EMPTY(), CLEANUP()], comment='*'),
...


db.define_table('Affiliations',
Field('Member', 'reference Members', writable=False),
Field('College', 'reference Colleges',
...

and a grid:

grid = Grid(db.Affiliations.Member==member_id,
orderby=db.Affiliations.Modified,
columns=[db.Affiliations.College, db.Affiliations.Matr, db.Affiliations.Notes],
details=not write, editable=write, create=write, deletable=write, show_id=True,
validation=affiliation_modified, search_queries=[],
grid_class_style=grid_style,
formstyle=form_style,
)


which shows a member's (possibly multiple) affiliations

With earlier versions of pydal the db.Affliations.College column display the Name of the college, based on the Colleges table's format, but new pydal versions show the integer college id.

I think this is a pydal issue?

Massimo DiPierro

unread,
Sep 1, 2025, 5:55:19 PM (6 days ago) Sep 1
to py4web
I added a commit and I think this is now fixed. But this default behavior is not very inefficient because requires a DB select for each raw in the referenced table. I am not convinced this is something I want to encourage. 

Instead this is what you want:

Gird(... columns=[Column("college", lambda row: row.Name, required_fields=[db.College.Name]), db.Affiliations.Matr,  db.Affiliations.Notes], ...)



David Manns

unread,
Sep 2, 2025, 11:57:45 AM (5 days ago) Sep 2
to py4web
Indeed it's working. I have a bunch of grids that depend on this, and this is the behavior described in https://py4web.com/_documentation/static/en/chapter-07.html#format-record-representation

I think the overhead is incurred only for the rows that are displayed, not all the rows selected by the query, so doesn't seem excessive? And this behavior is much more natural, as normally there is no reason to display the referenced record's id's in a grid. So I vote for keeping this as is!
Reply all
Reply to author
Forward
0 new messages