Production Collection Shows No data on First Load after login


On first login, sometimes the Cards collection shows no data (see attached image).
However, when an admin clicks on a different collection next, it shows the data on that collection.
Then going back to the original collection displays the data – with no error.
All other collections work as expected.

I have only noticed this on production - dev and staging seem fine.

Cards are the first collection an admin is taken on login. We have implemented a user scope by Company Name for most of the collections.


Do you have any logs on your forest backend/ in the web console ?

Thanks for getting back to me @Nicolas_Sailly

I am afraid I don’t. I neglected to look at the production logs yesterday, and I wasn’t able to reproduce the failure today. I will make sure to make a note of the production server logs when it happens again and post them here.


There is a a problem with your scopes and filtering by the userTags.
What is happening is sometimes it passes empty string ‘"’ to the controllers, sometimes it passes the correct variable. This is a totally random and unpredictable occurrence. The scopes are filled in correctly and the tags are filled in correctly, but forest is not passing the right variable/string consistently. We refresh that table and sometimes it works, sometimes it doesn’t.

This is how we setup the scopes:

scope by company_id

filter_company = lambda do |condition, where|
company_value = condition[‘value’]
case condition[‘operator’]
when ‘equal’
FROM card_transactions
JOIN cards ON = card_transactions.card_id
JOIN users ON = cards.user_id
JOIN companies ON = users.company_id
WHERE = ‘#{company_value}’)”

field :company, type: ‘String’, is_filterable: true, filter: filter_company do
# no performance issues identified by bullet in previous implementation,
# but added includes anyway. adding it doesn’t seem to make any difference. The reason is that we are looking
# for card transactions one by one
company = CardTransaction.where(id: [user: :company])


Example of the logs where it is passing nothing for the company field. @Nicolas_Sailly
FYI we cannot reproduce consistently. Sometimes it works sometimes it doesnt and we didn’t make any change from our side.

Parameters: {“fields”=>{“CardTransaction”=>“amount,created_at,receipt,card,vendor,expense_category,sync,user_email,currency,company”, “card”=>“user_name”, “vendor”=>“name”, “expense_category”=>“title”}, “searchExtended”=>“0”, “timezone”=>“Asia/Dubai”, “collection”=>“CardTransaction”}
2022-01-24T20:26:26.114151+00:00 app[web.1]: D, [2022-01-24T20:26:26.114056 #4] DEBUG – : [52f2f7d5-d051-46d3-a329-e15a6870efaa] (2.6ms) SELECT COUNT(*) FROM “card_transactions” WHERE (( IN (SELECT
2022-01-24T20:26:26.114153+00:00 app[web.1]: FROM card_transactions
2022-01-24T20:26:26.114154+00:00 app[web.1]: JOIN cards ON = card_transactions.card_id
2022-01-24T20:26:26.114154+00:00 app[web.1]: JOIN users ON = cards.user_id
2022-01-24T20:26:26.114155+00:00 app[web.1]: JOIN companies ON = users.company_id
2022-01-24T20:26:26.114155+00:00 app[web.1]: WHERE = ‘’)))

how we setup the scopes

Hello @Jonathan_Lau,

Sorry for the delay and thank you for the detailed answer.

Unfortunately, I wasn’t able to reproduce this bug on my end. Maybe I’m missing something. Could you please share the whole file where filter_company is defined ?


@NicolasGriselle @salim
We have been seeing this bug a lot again on staging and production yesterday. Today it seems to be working fine again. Keep in mine our production we have not done a deploy for 2 months - we have only been working on staging. So production environment there were no changes at all. But bug reappeard.

The only thing we can think of is a caching issue from forest admin. You guys are probably incorrectly caching something if there is heavy load. It is sending ‘’ instead of the correct usertag… pls advise.

@NicolasGriselle @salim

We are able to replicate the bug from before (the missing data/weird data records) - we can confirm it is a caching bug related to the scopes.

  1. a) Using one browser - Login with one account for company A to dashboard (with a scope for a company A) → data shows up fine in collections for company A

b) Using same browser - logout and then login with a DIFFERENT account (with a scope for company B) → company A data will show up in the dashboard for the company B account.

This is a caching issue. If we do it on two different laptops for the logins - it works ok. Pls advise ASAP - We are able to replicate this.

@Salim_Ameur @salim

:point_up: Discussion here :point_right: Bug for Scopes Caching