Repository navigation
fix(citations): resolve the ambiguous url reference in citation_url_ids - #743
Merged
Merged
Conversation
`returns table (id bigint, url text)` declares those names as PL/pgSQL variables, so `on conflict (url)` could mean the variable or the column and PL/pgSQL refuses to guess. The function raised on every call, which is worse than the bug it replaced: that one lost the answers with the most citations, this one lost all of them. 00059 was parsed with Postgres's grammar but never executed against a database, and the unit tests around this path mock the client, so neither could catch it. Parsing proves a function compiles, not that it runs. `#variable_conflict use_column` resolves an ambiguous name to the column, which is what every reference in this body means. Applied to the hosted database ahead of this commit rather than after it: the deployed write path was calling a function that raised for every answer, and leaving that in place until a merge would have cost another night of the nightly run. Verified against a real answer that had been failing since the start — 37 citations, 21,892 bytes of URL text, 26 ids returned. Refs #732
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
citation_url_idsfrom #741 raised on every call:returns table (id bigint, url text)declares those names as PL/pgSQL variables, soon conflict (url)inside the body could mean the variable or the column, and PL/pgSQL refuses to guess.That is worse than the bug it replaced. The old one lost the answers carrying the most citations; this one lost all of them.
#variable_conflict use_columnresolves an ambiguous name to the column, which is what every reference in this body means. Renaming the output columns would also work and would change the shape the caller reads, for no benefit.Why it got through
#741 was checked two ways, and neither could see this:
pglast). Parsing proves a function compiles, not that it runs — the ambiguity is raised at execution.The gap is that nothing executed the function against a database before it shipped. That is now the thing to change, not the specific mistake.
Applied ahead of merge
The hosted database has this already. The deployed write path was calling a function that raised for every answer, so leaving it until a merge would have cost another night of the nightly run writing no citation rows at all.
The repo was briefly behind the database, which is the drift #728 exists to prevent — this PR closes it, and the migration is
create or replace, so applying it again is a no-op.Verified against real data
Not mocked this time. Run against one of the answers that had been failing since the start:
That payload is precisely what overflowed the query string in the
.in()versions. It passes in the body.Also confirmed: a URL already in the dictionary comes back with its existing id rather than a new row, and a URL cited twice in one answer collapses to one entry.
What this means for the backfill
No new deploy is needed. The server already runs the code that calls this function, and the function now works — the backfill can be re-run as it stands.
Related issue
Refs #732 — phase 1 correction; the page still reads jsonb until phase 2.
Type of change
feat— New featurefix— Bug fixchore— Maintenance / dependenciesdocs— Documentation onlyrefactor— Code change that neither fixes a bug nor adds a featuretest— Adding or updating testsHow to test
Checklist
feature/,fix/,chore/,docs/) — see CONTRIBUTING.mdMigration only; no application code changes, so
server/andweb/are untouched.supabase/schema.sqlregenerated.