Skip stale-doc validation in ballot question sync#56
Merged
LexaMichaelides merged 1 commit intofeat/ballot-questionsfrom Apr 27, 2026
Merged
Skip stale-doc validation in ballot question sync#56LexaMichaelides merged 1 commit intofeat/ballot-questionsfrom
LexaMichaelides merged 1 commit intofeat/ballot-questionsfrom
Conversation
Member
|
lg, thanks! |
faf0759
into
feat/ballot-questions
10 of 11 checks passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The problem
syncBallotQuestionswas failing on dev with a runtypes validation error.Description of that problem
The script reads each existing Firestore doc and runs it through
BallotQuestion.checkWithDefaultsbefore the upsert — so it had to validate data it then overwrites. After commit79026eb6narrowedsupportCommittee/opposeCommitteefromArray(String)toUnion(String, Null), any pre-existing dev doc still holding the array shape blew up validation, and the sync exited before writing anything. The script couldn't repair the very state it was designed to repair.Changes in this PR
The script only consumes four fields off the existing snapshot (
testimonyCount,endorseCount,neutralCount,opposeCount) to preserve runtime-owned counters through the upsert. Validating the rest of the doc was incidental. Replaced theBallotQuestion.checkWithDefaults(snap.data())call with a plainsnap.data(). YAML input is still validated on read (line 27).Test
Reproduced against a local Firestore emulator:
ballotQuestions/23-34with the broken array shape (supportCommittee: ["Old Committee A", "Old Committee B"]) and non-zero counters.yarn firebase-admin --env=local run-script syncBallotQuestions --dir=...against a single YAML.supportCommitteeis now the YAML's string value,opposeCommitteeisnull, and the four counters were preserved (testimonyCount: 42,endorseCount: 30, etc.).So one sync run overwrites the stale array shape and self-heals the dev DB without a separate migration.