⚠ This page is served via a proxy. Original site: https://github.com
This service does not collect credentials or authentication data.
Skip to content

Conversation

@themavik
Copy link
Contributor

Summary

Fixes #5439

When refreshing topology data from a provider (e.g., ArgoCD, Cilium), the process_topology function deletes existing TopologyServiceDependency and TopologyService records before creating new ones. However, it does not delete TopologyServiceApplication rows that reference the services being deleted.

Since TopologyServiceApplication.service_id has a foreign key to TopologyService.id without ondelete=CASCADE, the deletion of TopologyService records fails with:

ForeignKeyViolation: update or delete on table "topologyservice" violates
foreign key constraint "topologyserviceapplication_service_id_fkey" on
table "topologyserviceapplication"

Changes

  1. Query service IDs first — collect all TopologyService.id values for the provider before deleting anything, so we can use IN clauses for targeted cleanup.

  2. Delete TopologyServiceApplication rows — remove the service-application associations before deleting the services themselves.

  3. Delete dependencies by ID — use the pre-collected service IDs with IN instead of the previous subquery through has(), which is both more explicit and avoids the need for the relationship-based filter. Also deletes reverse dependencies (where the service is the depends_on_service_id target).

  4. Delete services by ID — use the same pre-collected IDs for consistency.

Test Plan

  • Configure ArgoCD provider and verify topology pull completes without FK violation
  • Verify topology data is correctly refreshed (old services removed, new ones created)
  • Verify application associations are re-created after topology refresh
  • Test with Cilium provider (also reported in [🐛 Bug]: cilium topology pull error #5517)

Assisted by Claude Opus 4.6 max thinking

Made with Cursor

…t FK violation

When refreshing topology data from a provider (e.g., ArgoCD), the code
deletes TopologyServiceDependency and TopologyService records but does
not delete TopologyServiceApplication rows that reference those services.

Since TopologyServiceApplication.service_id has a foreign key to
TopologyService.id WITHOUT ondelete=CASCADE, the deletion of
TopologyService records fails with:

    ForeignKeyViolation: update or delete on table "topologyservice"
    violates foreign key constraint
    "topologyserviceapplication_service_id_fkey"

Fix: delete TopologyServiceApplication records for the affected services
before deleting the TopologyService records themselves.

Fixes keephq#5439
@vercel
Copy link

vercel bot commented Feb 10, 2026

@themavik is attempting to deploy a commit to the KeepHQ Team on Vercel.

A member of the Team first needs to authorize it.

@dosubot dosubot bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Feb 10, 2026
@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 10, 2026

Target branch is not in the allowed branches list.

@dosubot dosubot bot added the Bug Something isn't working label Feb 10, 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]: argocd topology pull error

2 participants