Repository navigation
Fix columns with the same name returning the wrong values - #34
Merged
CollierKing merged 1 commit intoOct 2, 2026
Merged
Conversation
The /raw rows were turned into dicts keyed by column name, and fetchone read the values back by name. When two columns shared a name, as in SELECT a.id, b.id or SELECT * over a join, the last one overwrote the others, so every one of them came back with the same value. Keep the rows as the arrays D1 sends and build the tuples by position. Worker rows from all() are still dicts and are read as before. Fixes CollierKing#31
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.
Problem
When a query returns two columns with the same name, every one of them gets the value of the last one (#31).
SELECT a.id, a.name, b.id FROM a JOIN b ON b.a_id = a.idreturns(7, 'x', 7)instead of(1, 'x', 7), andSELECT *over a join hits it whenever both tables have anid._execute_queryturned each/rawrow intodict(zip(columns, row)), andfetchoneread the values back by name.Fix
Keep the rows as the arrays
/rawsends and build the tuples by position, in bothConnectionandAsyncConnection. Worker rows come fromall()as dicts and are read as before.all()gives one object per row, so same-name columns are already merged there, and this PR does not change that path.Tests
tests/unit/test_connection.pywith fake/rawreplies throughhttpx.MockTransport: the sync cursor, the async cursor and a SQLAlchemy engine all return(1, 'x', 7). The new tests fail without the fix. Unit suite: 48 passed on Python 3.11 and 3.9.TestColumnsWithSameNameclass (join through the cursor,SELECT *over the join, join through SQLAlchemy). All 3 fail onmain. With the fix, the REST API and base URL integration files pass: 89 passed.ruff check,ruff format --diff,mypy src/,codespellandpre-commit run --all-filesare clean.This PR and #33 touch different lines and merge cleanly together.
Fixes #31