fix: delete TopologyServiceApplication links before TopologyService rows (fixes #5439)#6171
Open
chengyixu wants to merge 1 commit intokeephq:mainfrom
Open
Conversation
When process_topology refreshes provider topology data it deletes all existing TopologyService rows for that provider. If any of those services were associated with a TopologyApplication (via the TopologyServiceApplication join table), the delete violated the foreign-key constraint on topologyserviceapplication.service_id and raised: sqlalchemy.exc.IntegrityError: ForeignKeyViolation on topologyserviceapplication — topologyservice.id still referenced The fix deletes the TopologyServiceApplication join-table rows first, in the same transaction as the dependency and service deletes, using the same filter pattern already used for TopologyServiceDependency. Closes keephq#5439 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
@chengyixu is attempting to deploy a commit to the KeepHQ Team on Vercel. A member of the Team first needs to authorize it. |
Author
|
Hi team! This fixes the ForeignKeyViolation crash in process_topology (#5439). All CI checks passing. Happy to address any feedback! |
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
Fixes a
ForeignKeyViolationthat crashesprocess_topologywhenever a provider's topology services belong to a TopologyApplication.Root cause
process_topologyrefreshes topology data by deleting then re-inserting allTopologyServicerows for a given provider. The deletion order was:TopologyServiceDependency(correct — hasCASCADE)TopologyService(fails when a row is still referenced byTopologyServiceApplication.service_id)The
TopologyServiceApplicationjoin table does not haveON DELETE CASCADE, so step 2 raised:This is the exact traceback reported in #5439.
Fix
Delete the
TopologyServiceApplicationrows for the affected services before deleting theTopologyServicerows, using the same filter pattern already used forTopologyServiceDependency.Changes
keep/api/tasks/process_topology_task.py— addTopologyServiceApplicationdeletion steptests/test_topology.py— regression test that would have caught this (and confirms the fix)Closes #5439