Fix SourceSynchronizer silently dropping edits to translated attributes - #116
Merged
Conversation
compare_and_sync read local state with record.attributes.slice(*source_attributes).
Mobility is configured with backend :container and without the attribute_methods
plugin, so translated attributes (description, uses, cultivation, ...) live in the
translations jsonb and never appear in #attributes. Slicing there returned {} for
them, so local always looked different from the stored snapshot.
Consequences, both verified by the added spec before the fix:
- an unchanged re-sync was scored locally_modified instead of synced
- a genuine upstream edit to a translated attribute was silently dropped -
applied stayed 0, no conflict was raised, and the value never changed
Translated fields therefore stopped syncing after record creation, silently.
The existing suite missed this because SOURCE_ATTRS is scientific_name and
family_names, both real columns, and the one spec passing %w[description]
exercises the invalid-payload path, which returns before compare_and_sync.
Read through the public reader instead, so column-backed and translated
attributes behave identically. Applied at both call sites.
Full suite: 2307 examples, 0 failures. Rubocop clean.
This was referenced Aug 13, 2026
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.
What this fixes
SourceSynchronizer#compare_and_syncread local state with:Mobility is configured with
backend :containerand without theattribute_methodsplugin (config/initializers/mobility.rb), so translatedattributes —
description,uses,cultivationand the other 20-odd — liveinside the
translationsjsonb and never appear in#attributes. Slicing therereturns
{}for them, solocalalways looked different from the storedsnapshot.
Why it matters
Two symptoms, both reproduced in the added spec before the fix:
locally_modifiedrather thansynced.appliedstayed 0, noSyncConflictwas raised, and the value never changed.The second is the serious one. The failure that had been predicted from reading
the code was "spurious conflicts on every second run", which would at least be
visible. What actually happens is that translated fields stop syncing after
record creation, with nothing raised anywhere.
Why the suite didn't catch it
SOURCE_ATTRSinspec/services/source_synchronizer_spec.rbis%w[scientific_name family_names]— both real columns — and the idempotencyspec uses that default. The one spec that passes
%w[description]exercises theinvalid-payload path, which returns before
compare_and_syncis reached.The change
Read through the public reader instead of the attributes hash, so column-backed
and translated attributes behave identically. Applied at both call sites
(
compare_and_syncandhandle_source_deletion).A note on Mobility's
fallbacksplugin is included in the code comment: readinga missing locale returns the
:envalue, but sync writes and reads within thesame locale, so the comparison stays symmetric.
Verification
spec/services/source_synchronizer_translated_spec.rbcovers themechanism (translated attrs absent from
#attributes) and both symptoms.Context
Found while verifying risk R5 of the plant-data ownership migration, which plans
to use
SourceSynchronizerto reconcile ECHOcommunity plant data into this API.24 of the plant fields involved are translated, so this would have blocked that
work. The suspicion originated in
fpi-connector/docs/target-api-analysis.md,where it was explicitly labelled a code-reading conclusion needing verification.