-
-
Notifications
You must be signed in to change notification settings - Fork 298
Open
Labels
Waiting on ReproductionPending reproduction repository or detailed reproduction steps to proceed with issue resolution.Pending reproduction repository or detailed reproduction steps to proceed with issue resolution.
Description
Dashboard card hydration regression
Summary
Requests hitting Avo::Dashboards::CardsController#show
can raise NoMethodError: undefined method
hydrate' for nilafter the first dashboard render. The controller calls
card.hydrateon the result of
parent.item_at_index(params[:index]), but the lookup returns
nil` because card indices drift between requests.
Root cause
Avo::Dashboards::BaseDashboard
mixes inAvo::Cards::Concerns::HasCards
, which tracks acard_index
counter and acards_holder
array.- In Avo 3.24.x the concern stores
card_index
as aclass_attribute
. The counter therefore retains its value across instances and requests. - Every time the DSL method
card
is invoked,card_index
is incremented. - Rendering the dashboard page (first request) builds the card list and leaves the counter at the total number of items (e.g.
4
). - Each subsequent hydration request (triggered by the dashboard fetching
/cards/:id
) also callsfetch_cards
. Because the counter was never reset, the firstcard
invocation in that request assigns index4
instead of0
. As a resultitem_at_index(0)
returnsnil
, leading to the crash.
Reproduction steps
- Upgrade an app to Avo 3.24.x (the issue is tied to the
class_attribute
change inHasCards
). - Define a dashboard with at least one
card
indef cards
. - Load the dashboard in the browser.
- Observe that the initial render succeeds, but XHR calls to
/admin/dashboards/:dashboard/cards/:card_id
fail withNoMethodError: undefined method
hydrate' for nil`.
Suggested fix
Reset both the card_index
class attribute and the instance @cards_holder
before repopulating cards. This keeps indices aligned with the positions expected by the hydration controller.
class Avo::Dashboards::Base < Avo::Dashboards::BaseDashboard
def fetch_cards
self.class.card_index = 0
@cards_holder = []
super
end
end
Impacted versions
- Confirmed on Avo 3.24.1 (
avo-dashboards
3.24.1). - Not reproducible on earlier releases where
card_index
was stored per instance.
Related production issue
- Sentry issue
CORE-28
: repeated hits on/admin/dashboards/client/cards/clients_payouts_upcoming_metric
triggered the exception and impacted multiple users.
https://guestit-ab-dr.sentry.io/share/issue/99b041c0209d4bef82c53a7515af966b/
Metadata
Metadata
Assignees
Labels
Waiting on ReproductionPending reproduction repository or detailed reproduction steps to proceed with issue resolution.Pending reproduction repository or detailed reproduction steps to proceed with issue resolution.
Type
Projects
Status
To Do