Skip to content

fix(topology): preserve incident continuity and application identity across topology re-imports - #6740

Open
Prabal864 wants to merge 1 commit into
keephq:mainfrom
Prabal864:fix-6731-topology-reimport-duplicate-incidents
Open

fix(topology): preserve incident continuity and application identity across topology re-imports#6740
Prabal864 wants to merge 1 commit into
keephq:mainfrom
Prabal864:fix-6731-topology-reimport-duplicate-incidents

Conversation

@Prabal864

Copy link
Copy Markdown
Contributor

What

Fixes #6731.

When importing or re-importing topology YAML, TopologiesService.clean_before_import deletes all existing TopologyApplication records for the tenant. On recreation, create_applications_by_tenant_id assigns brand new internal UUIDs to applications that do not specify explicit IDs in YAML.

Because topology incidents link to applications via Incident.incident_application == application.id, TopologyProcessor._get_application_based_incident fails to locate the active incident for the recreated application and creates a duplicate incident when subsequent alerts fire.

Fix

  1. In TopologiesService.import_to_db, query existing application IDs by (tenant_id, name) before cleanup, and preserve the existing UUID for matching applications.
  2. In TopologyProcessor._get_application_based_incident, if lookup by application.id misses, fall back to looking up an active non-deleted topology incident by application name (Application incident: {application.name}) and re-link incident.incident_application = application.id.

Testing

  • Updated tests/test_topology.py::test_import_to_db to assert that application IDs remain stable across successive imports.
  • Added test_get_application_based_incident_fallback_by_name to assert that an existing active incident created under a prior application UUID is found and reconnected to the new application ID.
  • python -m py_compile passes cleanly on all changed files.

Checklist

  • I have read the Contributing Guide
  • If you've added code that should be tested, add tests.
  • If you've changed APIs, update the documentation.
  • Ensure the test suite passes.
  • Make sure your code lints (black/isort)

@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. Bug Something isn't working labels Aug 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Something isn't working size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[🐛 Bug]: Topology Re-import Creates Duplicate Application Incidents

1 participant