Skip to content

fix(downtime_schedules): reconcile destination conflicts - #656

Merged
michael-richey merged 1 commit into
mainfrom
michael.richey/downtime-schedules-conflict-skip
Aug 3, 2026
Merged

fix(downtime_schedules): reconcile destination conflicts#656
michael-richey merged 1 commit into
mainfrom
michael.richey/downtime-schedules-conflict-skip

Conversation

@michael-richey

@michael-richey michael-richey commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator

Summary

Handle deterministic downtime destination conflicts without leaving stale or unmanaged state.

What this PR changes

  • On a duplicate-create 400, parse the structured API error. If it identifies exactly one existing downtime, fetch that resource and persist its source-to-destination mapping.
  • If a duplicate response has no candidate ID or multiple candidate IDs, preserve the original error so normal failure accounting remains visible.
  • On an update 404 with the specific Downtime not found error, recreate the downtime and replace the stale destination mapping with the new response.
  • Propagate unrelated update 404 responses.
  • Treat delete 404 as an idempotent success.

Test plan

  • Duplicate-create reconciliation persists the existing destination resource.
  • Missing and ambiguous duplicate IDs propagate.
  • Update-not-found recreation replaces stale state and omits the obsolete destination ID.
  • Unrelated update 404 and other 4xx/5xx responses propagate.
  • Delete 404 remains idempotent.
  • Focused downtime tests pass.
  • Non-subprocess unit suite passes.
  • Ruff and Black checks pass.

Recover an unambiguous duplicate create by fetching and persisting the existing destination downtime. Reject ambiguous duplicate responses so unmanaged resources are not silently accepted.

When an update reports that its mapped downtime is gone, recreate it and replace the stale mapping. Other 404 responses continue through normal failure accounting. Keep delete 404 handling idempotent.

Add regression coverage for state replacement, duplicate reconciliation, ambiguous conflicts, unrelated 404 responses, and sibling progress.
@michael-richey
michael-richey force-pushed the michael.richey/downtime-schedules-conflict-skip branch from 76b02d1 to 82d8d59 Compare August 3, 2026 18:15
@michael-richey michael-richey changed the title fix(downtime_schedules): skip duplicate-create 400 and gone 404 instead of failing fix(downtime_schedules): reconcile destination conflicts Aug 3, 2026
@michael-richey
michael-richey requested a review from Copilot August 3, 2026 18:18

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves downtime_schedules sync robustness by handling deterministic destination-side conflict and “gone” conditions in a way that avoids leaving stale/unmanaged destination mappings, while still propagating unrelated failures for normal retry/accounting.

Changes:

  • Reconcile create-time duplicate (400) by parsing the structured error body, fetching the single unambiguous existing downtime, and persisting its mapping.
  • Handle update-time not-found (404 with “Downtime not found”) by recreating the downtime and replacing the stale destination mapping; propagate unrelated 404s.
  • Expose HTTP response bodies on CustomClientHTTPError to enable structured error parsing, and add focused unit tests for the new behaviors (including delete 404 idempotency).

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
datadog_sync/model/downtime_schedules.py Adds deterministic conflict/not-found handling for create/update/delete and factors create-schedule normalization into a helper.
datadog_sync/utils/resource_utils.py Extends CustomClientHTTPError to retain the response body for downstream error inspection.
tests/unit/test_downtime_schedules_conflict_skip.py Adds unit coverage for duplicate-create reconciliation, update-not-found recreation, and delete 404 idempotency.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@michael-richey
michael-richey marked this pull request as ready for review August 3, 2026 18:51
@michael-richey
michael-richey requested a review from a team as a code owner August 3, 2026 18:51
@michael-richey
michael-richey merged commit dae2d4d into main Aug 3, 2026
22 of 23 checks passed
@michael-richey
michael-richey deleted the michael.richey/downtime-schedules-conflict-skip branch August 3, 2026 20:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants