Skip to content

[Onyx] Native Onyx.merge persists different values to SQLite than the cache #105485

Todo

Description

@MelvinBot

Problem

On native, Onyx.merge can write a different value to SQLite than the one it keeps in the cache. After an app restart, Onyx loads the SQLite value, so the app can show stale data.

This happens in two cases:

  1. New key with null properties. For a key that has no stored value yet, null should remove the property. The cache drops it, but SQLite stores the null. The SQLite upsert applies JSON_PATCH only to existing rows, so a new row stores the merge delta unchanged.
  2. Batched null reset. When a merge batch for a key contains null followed by a new object, SQLite keeps the old fields instead of replacing the value.
await Onyx.merge('test', {keep: true, remove: null});

// Cache:  {keep: true}
// SQLite: {keep: true, remove: null}

Reproduction

In an initialized native Onyx development build with two registered test keys:

  1. Set the first test key to {old: true}.
  2. Queue a merge batch for that key containing null followed by {new: true}.
  3. Export persisted state with Onyx.exportState().
  4. Merge {nested: {keep: true, remove: null}} into the previously unused second key.
  5. Export persisted state again.

Expected: The first key contains only {new: true}, and the second key contains only {nested: {keep: true}}.

Actual: SQLite keeps the old fields for the first key and keeps remove: null for the second key.

Fix

Issue OwnerCurrent Issue Owner: @ZhenjaHorbach

Activity

  1. added
    Reviewing
    Weekly
    on Oct 30, 2026
  2. expensify-chore-bot commented on Nov 23, 2026

    @expensify-chore-bot

    Triggered auto assignment to @marcochavezf, see https://stackoverflow.com/c/expensify/questions/7972 for more details.

  3. self-assigned this
    on Nov 23, 2026
  4. added
    Daily
    and removed
    Reviewing
    Weekly
    on Nov 25, 2026
  5. melvin-bot commented on Nov 25, 2026

    @melvin-bot

    ⚠️ Failed to process issue for release 9.5.53-3

    Details
    Github\Exception\RuntimeException
    
  6. melvin-bot commented on Nov 25, 2026

    @melvin-bot

    ⚠️ Failed to process issue for release 9.5.53-3

    Details
    Github\Exception\RuntimeException
    
  7. added
    Reviewing
    on Nov 26, 2026
  8. expensify-chore-bot commented on Dec 3, 2026

    @expensify-chore-bot

    @ZhenjaHorbach Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!

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

Metadata

Metadata

Labels

DailyReviewing

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions