Fix _col=<pk> producing duplicate column in output#2774
Merged
Conversation
When `_col=<pk_column>` is passed, the column is emitted twice in the SELECT
because `_columns_to_select` starts `columns` with the pks and then extends
it with the deduplicated `_col` values without re-checking against the
already-added pks. Visible as:
/blog_entry.csv?_col=id&_col=title&_col=body
id,id,title,body
1,1,WaSP Phase II,...
Skip `_col` values that are already in `columns` (the pks) when extending.
The pks still appear first in the configured order; ordering of any
additional `_col` values is unchanged.
Added two regression cases to `test_col_nocol`: `?_col=pk` and
`?_col=pk&_col=state`, both linked to the issue.
Owner
|
I confirmed that the new tests fail without this fix: |
Owner
|
Thanks for this! |
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.
Fixes:
When
_col=<pk_column>is passed (e.g.?_col=id&_col=title&_col=bodyon a table whose pk isid),_columns_to_selectstartscolumnswith the pks and then extends it with the deduplicated_collist — but the dedup is only within_colitself, not against the pks already incolumns. Soidends up in the SELECT twice:This skips
_colvalues that already appear incolumns(i.e. the pks) when extending:Behavior notes:
_colvalues is unchanged._col=state&_col=statededup-within-_colbehavior is preserved._nocolinteraction is unchanged — it still filters the final list.Added two regression cases to
test_col_nocol, both linked to the issue:?_col=pk&_col=state→["pk", "state"]?_col=pk→["pk"]Also probed multi-pk tables (
pk=[a,b]) and pk-only requests; both produce the expected dedup behavior.Prepared with AI assistance.