You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
accounts: Invariant that active account exists when we expect it to
In its handling of the actions REGISTER_COMPLETE, LOGOUT,
DISMISS_SERVER_PUSH_SETUP_NOTICE, and EVENT, the `accounts` reducer
has been making the unchecked assumption that there is an active
account.
When there isn't an active account (perhaps because the last account
was removed with ACCOUNT_REMOVE), the reducer has been creating
badly typed partial `Account`s, by creating an object from a spread
of `state[0]` which is `undefined`. For example, with
REGISTER_COMPLETE:
{
...state[0],
userId: action.data.user_id,
zulipFeatureLevel: action.data.zulip_feature_level,
zulipVersion: action.data.zulip_version,
lastDismissedServerPushSetupNotice: action.data.realm_push_notifications_enabled
? null
: state[0].lastDismissedServerPushSetupNotice,
}
That will make an object with only userId, zulipFeatureLevel,
zulipVersion, and lastDismissedServerPushSetupNotice. When code
expects a well-formed Account including realm, apiKey, email, and
ackedPushToken, it'll error.
Flow has basically let this happen because it assumes (wrongly, in
this case) that `state[0]` is an in-bounds access that will give an
Account.
We've had a few mysterious Sentry reports where it seems `realm` is
missing in the active account. E.g., for those with access:
https://sentry.io/organizations/zulip/issues/3900597161/?project=191284https://sentry.io/organizations/zulip/issues/3900597257/?project=191284https://sentry.io/organizations/zulip/issues/3900597246/?project=191284https://sentry.io/organizations/zulip/issues/3900596985/?project=191284
Seeing that the faulty reducer code could cause that symptom, add an
`invariant` that there is an active account. (And fix some
mute-model test data where the data was unrepresentative because it
was missing an active account.)
N.B.: The new invariant ensures that there *is* an active account,
but it doesn't check that it's the account the action was supposed
to act on. We should fix that (so, add TODOs about it), but at least
now we hope to be rid of these malformed `Account` objects.
Not seeing anything else that could cause these malformed Account
objects, add a migration so they don't come up from storage.
0 commit comments