Don't load smart field in collection view

Feature(s) impacted

Collection (list) view

Observed behavior

When querying a page of items in the collection, i.e the “list” view, all fields get loaded, including smart fields, etc.

Expected behavior

I’d like this to be customisable as some smart fields we have configured are very resource intensive. Ideally, I’d like to mark a smart field to be loaded in the detail/summary view of a single record.

Hello and welcome,
You can manage your list view with this section of the documentation.
Let me know if it is ok for you :pray:

Hey! Thank you for the response. Alas, I’ve already done this – my API still gets hit for the smart field, even though it is not selected to be shown in the list view.

Could you send me the http request sent by the frontend please ? And tell me if you find your smart field inside. You can find it in the “network” section from the web inspector.

Yep, will attach.

The request URL:

http://localhost:8000/forest/core_business?timezone=Australia/Sydney&fields[core_business]=id,registered_name,trading_name,kyc_status,status,allow_new_transaction_view,uses_upfront_billing,Last Balance&page[number]=1&page[size]=15&sort=-id

The smart field in particular, is not included in that list of fields. I can also confirm that the smart field does also not get returned in the response.

The problem however, is that the smart field’s value is in fact calculated.

Here is some of the Forest Admin Django plugin’s call trace

ListView::getListView::handle_smart_fields

In here it simply goes: smart_fields = [x for x in collection['fields'] if x['is_virtual']] which I can imagine is the problem, as it’s not respecting the query. It then calls handle_get_method for each smart field.

Only on the way out, in ListView::serialize are the request’s parameters respected, and this is where the hidden smart field is stripped out.

Thus, the problem exists that every query hits every smart field.

1 Like

Hi @lucasob,

Thanks for your PR, I’ll check it soon.