fix(synthetics_global_variables): key on (name, type) to resolve 409 conflict#564
Merged
michael-richey merged 1 commit intoMay 15, 2026
Merged
Conversation
…conflict
The Datadog API enforces uniqueness on the (name, type) tuple — two
global variables can share a name as long as their types differ. Keying
`_existing_resources_map` by `name` alone caused last-write-wins map
collisions: when the destination had two variables with the same name
but different types, only one survived in the prefetch map and the
source matching the other type fell through to POST and hit
"409 Conflict — Synthetics variable with same name and type already
exists".
Switch `resource_mapping_key` to `lambda r: f"{r['name']}:{r['type']}"`,
mirroring the composite-key pattern Teams already uses for (name, handle).
The existing prefetch + remap path in `create_resource` then resolves
conflicts before any POST is issued.
Adds six unit tests in tests/unit/test_synthetics_global_variables.py
covering: map_existing_resources retains both same-name variants,
routing by composite key, key-resolves-to-string + missing-type-returns-None
guards, unique-name regression, and the partial-collision case that
reproduces the production bug.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
heyronhay
approved these changes
May 15, 2026
michael-richey
added a commit
that referenced
this pull request
May 15, 2026
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Merged
michael-richey
added a commit
that referenced
this pull request
May 15, 2026
* Update CHANGELOG * Update CHANGELOG: add #564 to 4.4.0 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> --------- Co-authored-by: dd-octo-sts[bot] <200755185+dd-octo-sts[bot]@users.noreply.github.com> Co-authored-by: michael.richey <michael.richey@datadoghq.com> Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Summary
Resolves intermittent 409 Conflict on `datadog-sync sync` for `synthetics_global_variables`:
Root cause. `datadog_sync/model/synthetics_global_variables.py:36` keyed `_existing_resources_map` by `name` only, but the Datadog API enforces uniqueness on the `(name, type)` tuple. When the destination had two variables sharing a name across different types (e.g. `type=variable` and `type=secret_token`), only one survived the last-write-wins collision in the prefetch map. The source variable matching the other type fell through to `POST` and hit the 409.
Fix. Switch `resource_mapping_key` to a composite lambda `lambda r: f"{r['name']}:{r['type']}"`. The existing prefetch + remap path in `create_resource` then resolves conflicts before any POST is issued — no new try/except, no new API call. This mirrors the pattern `Teams` already uses at `datadog_sync/model/teams.py:34` for its `(name, handle)` uniqueness, with the key difference that Synthetics is v1-flat (lambda reads `r['name']` / `r['type']` directly, not `attributes.name` / `attributes.handle`).
Tests
Six unit tests in `tests/unit/test_synthetics_global_variables.py`:
3a. Composite key resolves to `"X:variable"` on full input (red→green).
3b. Missing `type` returns `None` silently — guards `base_resource.py:111-115` silent-fail path against future refactors.
All 6 pass; full `tests/unit/` suite (576 tests) green; `tox -e ruff,black` clean.
Cassette note
Existing integration test `tests/integration/resources/test_synthetics_global_variable.py` is unaffected: the destination state fixture at `resources/destination/synthetics_global_variables.json` contains a single variable with a unique name, so the new composite key collapses to the same single-entry map as the old name-only key. No cassette re-record required. (The current cassettes have pre-existing playback failures on `main` unrelated to this fix.)
Out of scope
Test plan
🤖 Generated with Claude Code