Skip to content

[Onyx bump] Version 3.0.88: Split queries with many parameters into multiple queries to avoid too many SQL variables error#94947

Open
chrispader wants to merge 5 commits into
Expensify:mainfrom
margelo:@chrispader/fix-sqlite-too-many-sql-variables-error
Open

[Onyx bump] Version 3.0.88: Split queries with many parameters into multiple queries to avoid too many SQL variables error#94947
chrispader wants to merge 5 commits into
Expensify:mainfrom
margelo:@chrispader/fix-sqlite-too-many-sql-variables-error

Conversation

@chrispader

@chrispader chrispader commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

@mountiny

Explanation of Change

Bumps Onyx to version 3.0.88 which includes the following fix:

This PR fixes an issue in Onyx with SQLite where in some cases, very large Onyx DBs with lots of keys would cause queries with IN (...) to exceed the number of allowed parameters per query (usually more than 32,766, as per https://sqlite.org/limits.html).

Fixed Issues

$ #94577 (comment)
PROPOSAL:

Tests

  • Verify that no errors appear in the JS console

To reproduce this error, we must manually add some code to the app locally:

  1. Add this useEffect in

    App/src/App.tsx

    Lines 73 to 144 in 371c63d

    function App() {
    useDefaultDragAndDrop();
    OnyxUpdateManager();
    return (
    <StrictModeWrapper>
    <SplashScreenStateContextProvider>
    <InitialURLContextProvider>
    <HybridAppHandler />
    <GestureHandlerRootView style={fill}>
    {/* Initialize metrics early to ensure the UI renders even when NewDot is hidden.
    This is necessary for iOS HybridApp's SignInPage to appear correctly without the bootsplash.
    See: https://github.com/Expensify/App/pull/65178#issuecomment-3139026551
    */}
    <SafeAreaProvider
    initialMetrics={{
    insets: {top: 0, right: 0, bottom: 0, left: 0},
    frame: {x: 0, y: 0, width: 0, height: 0},
    }}
    >
    <View
    style={fill}
    fsClass={CONST.FULLSTORY.CLASS.UNMASK}
    >
    <ComposeProviders
    components={[
    OnyxListItemProvider,
    CurrentUserPersonalDetailsProvider,
    LocaleContextProvider,
    ThemeProvider,
    ThemeStylesProvider,
    ThemeIllustrationsProvider,
    SVGDefinitionsProvider,
    HTMLEngineProvider,
    PortalProvider,
    SafeArea,
    PopoverContextProvider,
    CurrentReportIDContextProvider,
    ConciergeSessionProvider,
    ScrollOffsetContextProvider,
    PickerStateProvider,
    EnvironmentProvider,
    CustomStatusBarAndBackgroundContextProvider,
    ActiveElementRoleProvider,
    ActionSheetAwareScrollViewProvider,
    KeyboardProvider,
    KeyboardStateProvider,
    InputBlurContextProvider,
    FullScreenBlockingViewContextProvider,
    FullScreenLoaderContextProvider,
    ModalProvider,
    SidePanelContextProvider,
    EditingCellProvider,
    ]}
    >
    <CustomStatusBarAndBackground />
    <ErrorBoundary errorMessage="NewExpensify crash caught by error boundary">
    <ColorSchemeWrapper>
    <Expensify />
    </ColorSchemeWrapper>
    </ErrorBoundary>
    <NavigationBar />
    </ComposeProviders>
    </View>
    </SafeAreaProvider>
    </GestureHandlerRootView>
    </InitialURLContextProvider>
    </SplashScreenStateContextProvider>
    </StrictModeWrapper>
    );
    }
    :
import React, {useEffect} from 'react';
import Onyx from 'react-native-onyx';
import type {OnyxMultiSetInput} from 'react-native-onyx';
import OnyxUtils from 'react-native-onyx/dist/OnyxUtils';

function App() {
    // ...

    useEffect(() => {
        // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
        const data = Array(33000)
            .fill(0)
            .reduce<Record<string, string>>((acc, _, i) => {
                const key = `TooManyVariablesDemo-${i}`;
                acc[key] = key;
                return acc;
            }, {}) as unknown as OnyxMultiSetInput;

        Onyx.multiSet(data).then(() => {
            OnyxUtils.getAllKeys().then((keys) => {
                console.log(`[TooManySQLVariablesDemo] Number of keys in Onyx: ${keys.size}`);
            });
        });
    }, []);

    // ...
}
  1. Add an explicit catch block to the clearOnyxAndResetApp function in

    App/src/libs/actions/App.ts

    Lines 879 to 933 in 371c63d

    function clearOnyxAndResetApp(shouldNavigateToHomepage?: boolean) {
    // The value of isUsingImportedState will be lost once Onyx is cleared, so we need to store it
    const isStateImported = isUsingImportedState;
    rollbackOngoingRequest();
    const sequentialQueue = getAll();
    Navigation.clearPreloadedRoutes();
    // Seed LAST_FULL_RECONNECT_TIME so subscribeToFullReconnect doesn't fire a duplicate
    // ReconnectApp once the openApp() below lands NVP_RECONNECT_APP_IF_FULL_RECONNECT_BEFORE.
    const resetPromise = clearWorkboxRecoveryCaches().then(() =>
    clearOnyxAndSeedFullReconnect(KEYS_TO_PRESERVE)
    .then(() => {
    // Network key is preserved, so when exiting imported state, we should:
    // 1. Stop forcing offline mode so the app can reconnect
    // 2. Clear the IS_USING_IMPORTED_STATE flag
    // 3. Restore the original user session
    if (isStateImported) {
    setShouldForceOffline(false);
    Onyx.set(ONYXKEYS.IS_USING_IMPORTED_STATE, false);
    Log.info('[ImportedState] Exiting imported state mode, restoring original session');
    }
    if (shouldNavigateToHomepage) {
    Navigation.navigate(ROUTES.HOME);
    }
    if (preservedUserSession) {
    Onyx.set(ONYXKEYS.SESSION, preservedUserSession);
    Onyx.set(ONYXKEYS.PRESERVED_USER_SESSION, null);
    }
    if (preservedAccount) {
    Onyx.set(ONYXKEYS.ACCOUNT, preservedAccount);
    Onyx.set(ONYXKEYS.PRESERVED_ACCOUNT, null);
    }
    })
    .then(() => {
    // Requests in a sequential queue should be called even if the Onyx state is reset, so we do not lose any pending data.
    // However, the OpenApp request must be called before any other request in a queue to ensure data consistency.
    // To do that, sequential queue is cleared together with other keys, and then it's restored once the OpenApp request is resolved.
    // When exiting imported state, force openApp to run even though the variable might not be updated yet
    openApp(false, undefined, isStateImported).then(() => {
    if (!sequentialQueue || isStateImported) {
    return;
    }
    for (const request of sequentialQueue) {
    save(request);
    }
    });
    }),
    );
    clearSoundAssetsCache();
    return resetPromise;
    }
function clearOnyxAndResetApp(shouldNavigateToHomepage?: boolean) {
    // ...

    const resetPromise = clearWorkboxRecoveryCaches().then(() =>
    clearOnyxAndSeedFullReconnect(KEYS_TO_PRESERVE)
        .then(() => {
            // ...
        })
        .catch((error) => {
            Log.alert('[TooManySQLVariablesDemo] Error clearing Onyx', {error});
        }),
    );

    return resetPromise
}
  1. Run the app and open the developer tools.
  2. Make sure that the [TooManySQLVariablesDemo] Number of keys in Onyx: <number of keys in Onyx> log appears with at least more than 32,766 keys (as this is the configured limit for number of parameters/variables in a query)
  3. Add a breakpoint in the .catch((error) => { ... }) block from step 2
  4. Make sure the breakpoint is hit without the fix from this PR and that the error reads as the following:
[NativeNitroSQLiteException][SqlExecutionError] too many SQL variables
  1. Repeat steps 1-5 with the fix in place and make sure that the breakpoint is not hit and no error is thrown.

Offline tests

None needed.

QA Steps

  • Verify that no errors appear in the JS console

Same as in Tests.

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • If new assets were added or existing ones were modified, I verified that:
    • The assets are optimized and compressed (for SVG files, run npm run compress-svg)
    • The assets load correctly across all supported platforms.
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • I added unit tests for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

Android: Native

Before fix:

Screen.Recording.2026-06-30.at.17.27.42.mov

After fix:

after.mov

@chrispader chrispader requested a review from a team as a code owner June 30, 2026 10:44
@melvin-bot melvin-bot Bot requested review from ChavdaSachin and removed request for a team June 30, 2026 10:44
@melvin-bot

melvin-bot Bot commented Jun 30, 2026

Copy link
Copy Markdown

@ChavdaSachin Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ This PR is possibly changing native code and/or updating libraries, it may cause problems with HybridApp. Please check if any patch updates are required in the HybridApp repo and run an AdHoc build to verify that HybridApp will not break. Ask Contributor Plus for help if you are not sure how to handle this. ⚠️

@chrispader chrispader changed the title chore: bump Onyx to version [Onyx bump] Version 3.0.88: Split queries with many parameters into multiple queries to avoid too many SQL variables error Jun 30, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a706ef06e9

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread package.json Outdated
@mountiny mountiny self-requested a review June 30, 2026 10:54
@github-actions

github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

🚧 mountiny has triggered a test Expensify/App build. You can view the workflow run here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant