Repository navigation
fix: don't lose aliases when deserializing duplicate or malformed data - #356
Open
Kevin Turcios (KRRT7) wants to merge 1 commit into
Open
Kevin Turcios (KRRT7) wants to merge 1 commit into
Kevin Turcios (KRRT7) wants to merge 1 commit into
Conversation
SqliteRelatedTermsAliases.deserialize and set_related_terms used a plain INSERT, so an alias listed twice raised IntegrityError on the (term, alias) primary key; add_related_term already used INSERT OR IGNORE, and the memory index keeps the first copy. deserialize also deleted the existing aliases before parsing its input, in both backends, so duplicate or malformed data left the index empty. Parse first, then replace, and ignore duplicates. Co-authored-by: wtfyd-agent[bot] <328989958+wtfyd-agent[bot]@users.noreply.github.com>
Bernhard Merkle (bmerkle)
approved these changes
Oct 18, 2026
Bernhard Merkle (bmerkle)
left a comment
Collaborator
There was a problem hiding this comment.
LGTM — verified locally.
This branch has not been deployed
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
SqliteRelatedTermsAliases.deserializeandset_related_termsused a plainINSERT, so an alias listed more than once (for example the sametermTextin two items) raisedsqlite3.IntegrityError: UNIQUE constraint failedon the(term, alias)primary key.add_related_termalready usesINSERT OR IGNORE, and the memory alias index keeps the first copy. Both now useINSERT OR IGNORE.deserializedeleted the existing aliases before parsing its input, in both the SQLite and memory backends. Duplicate (SQLite) or malformed (both) data therefore raised after the existing aliases were already gone. Both backends now parse the whole input first and only then replace the stored aliases, so a failed deserialize leaves them intact.Validation
KeyErrorwithout losing existing aliases. Plus a SQLite test forset_related_termswith duplicates. All fail without the fix (except the duplicate case on memory, which already worked).