fix(api): sync public key tags on update#6340
Merged
gustavosbarreto merged 1 commit intoMay 20, 2026
Merged
Conversation
PublicKeyUpdate only updated the public_keys row, leaving the public_key_tags junction table untouched. Editing a key to drop or replace its tags left the stale relationships in place, so removed tags reappeared on the next read. Re-sync the junction entries within a transaction so the persisted filter matches the request.
|
Claude finished @luizhf42's task in 3m 11s —— View job Code Review CompleteReviewed 1 file across code quality, security, testing, Go patterns, and architecture — no issues found. The code looks good as-is. Summary: The delete-then-reinsert approach for syncing junction table rows is correct and mirrors the existing If you push additional changes and want a new review, tag |
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.
What
Fixes public key updates silently keeping stale tag filters. Editing a key to remove or replace its tags now correctly drops the old tag relationships.
Why
PublicKeyUpdatein the Postgres store only updated thepublic_keysrow. Tags are a many-to-many relationship stored in thepublic_key_tagsjunction table, which was never touched on update — only on create. As a result, removed tags persisted and reappeared on the next read.Observed reproduction:
ANDtags (invalid state).The hostname field reset correctly because it is a plain column on
public_keys; only the junction-table relationships were orphaned.Changes
PublicKeyUpdatenow re-syncs thepublic_key_tagsjunction table — it deletes the existing entries for the key and re-inserts the current set, mirroring the tag-handling already done inPublicKeyCreate.WithTransactionso a partial failure cannot leave the key with mismatched filters.Testing
Verify with a key that has a tags filter: edit it to a hostname filter and confirm the tags are gone, then edit it to clear all filters and confirm both hostname resets to
.*and the tags array is empty.