Skip to content

Clean update mask paths that are missing from the saved data - #424

Open
pierre-su wants to merge 2 commits into
masterfrom
clean-update-mask-stale-paths
Open

Clean update mask paths that are missing from the saved data#424
pierre-su wants to merge 2 commits into
masterfrom
clean-update-mask-stale-paths

Conversation

@pierre-su

Copy link
Copy Markdown
Contributor

Summary

A map-valued field that is set and then cleared to null in the same save leaves stale nested leaf paths (e.g. brickValues.X.selectedId) in the update mask while the data at brickValues.X is now null. Firestore Web rejects such a mask with

Field 'brickValues.X.selectedId' is specified in your field mask but missing from your input data.

so saveDoc throws and the document is not saved. The REST path (Dart backend) would instead silently delete the field — also wrong.

Changes

  • New shared helper cleanUpdateMask in yust_database_service_shared.dart:
    • For each mask path: keep it if it resolves to an existing field in the data (value may be null); otherwise collapse it to the nearest existing ancestor (so the parent's null still gets written), or drop it entirely.
    • Collapse overlapping ancestor/descendant paths (Firestore rejects overlapping field paths) and deduplicate.
  • Applied at the DB boundary in both saveDoc implementations (Flutter SetOptions(mergeFields:) and Dart REST patch) and in commitTransaction (same masked REST write, same silent-delete risk).

The rule only removes invalid mask paths, so it is behaviour-neutral for already-consistent masks.

Tests

  • New unit tests for cleanUpdateMask covering map→null stale paths, ancestor collapsing, overlap/dedup, valid map masks, scalar fields, missing paths, and backtick-quoted segments.
  • dart analyze and flutter test pass (via fvm, Flutter 3.38.3).

🤖 Generated with Claude Code

@pierre-su
pierre-su requested a review from sinnaj-r July 27, 2026 06:44
@pierre-su pierre-su self-assigned this Jul 27, 2026
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