Production Collection Shows No data on First Load after login

Hello,

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.

Thanks!

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

Thanks for getting back to me @anon94532230

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.

Thanks!

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’
“card_transactions.id IN (SELECT card_transactions.id
FROM card_transactions
JOIN cards ON cards.id = card_transactions.card_id
JOIN users ON users.id = cards.user_id
JOIN companies ON companies.id = users.company_id
WHERE companies.name = ‘#{company_value}’)”
end
end

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: object.id).includes(card: [user: :company]).first.card.user.company
“#{company.name}”
end

@anon94532230

Example of the logs where it is passing nothing for the company field. @anon94532230
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 ((card_transactions.id IN (SELECT card_transactions.id
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 cards.id = card_transactions.card_id
2022-01-24T20:26:26.114154+00:00 app[web.1]: JOIN users ON users.id = cards.user_id
2022-01-24T20:26:26.114155+00:00 app[web.1]: JOIN companies ON companies.id = users.company_id
2022-01-24T20:26:26.114155+00:00 app[web.1]: WHERE companies.name = ‘’)))



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 ?

Thanks.

@anon15528774 @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.

@anon15528774 @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