field.represent is ignored for reference fields in grid

25 views
Skip to first unread message

laundmo

unread,
Sep 3, 2025, 6:50:04 AM (4 days ago) Sep 3
to py4web
Hi Massimo,

I'm using field.represent for reference fields basically everywhere across my app. The recent commit "make grid formatters_by_type always overrule field.represent for automatic Columns" completely breaks that, as field.represent is skipped for all reference fields.

I would highly encourage you to revert this commit, or at least ensure field.represent can still be used. Currently, I would need to use a manual Column() in each Grid, each time I include the field. This is a lot of boilerplate that previously wasn't necessary.

You even said yourself that the formatters_by_type can probably be deprecated entirely. So why did you suddenly do a complete 180 on this and make it the ONLY way to format reference fields?

> Yes this broke when fields in pydal were given all a default represent function. I think we should just deprecate FORMATTERS_BY_TYPE.
> Do we really want need the checkboxes?

For now, i will have to stay on an older version just before that commit.

FYI: My logic for field.represent on reference fields works like this: I created a DB view for each table which adds *_represent columns for each reference field. These are then added to Grid.required_fields by my Grid subclass, and used in field.represent if they are part of the row passed to field.represent. This is done to avoid repeated single-row queries caused by the built-in methods of representing reference fields, as those were a significant performance issue for some of my tables which have 10+ reference fields. (15 rows per grid page * 10 reference fields = 150 single-row queries per grid page)

- laundmo

laundmo

unread,
Sep 3, 2025, 7:12:36 AM (4 days ago) Sep 3
to py4web
I created a PR with a fix for this which is a bit nicer than just reverting that commit. The PR makes Grid prefer custom user-set field.represent over self.formatters_by_type. That keeps formatters_by_type behaviour for Reference fields (which uses table._format of the referenced table) intact unless the user ovewrote this with field.represent.

laundmo

unread,
Sep 3, 2025, 7:12:45 AM (4 days ago) Sep 3
to py4web

Massimo DiPierro

unread,
12:32 AM (10 hours ago) 12:32 AM
to py4web
I am sorry. I reverted my original change. It creates too many problems and exception. Please check master and see if this is acceptable.
Reply all
Reply to author
Forward
0 new messages