Open
Conversation
- Add Database.transaction() context manager using contextvars - All existing db.t.* calls automatically participate in active transaction - Fix _ColsGetter.__call__: .columns -> .cols
erikgaas
commented
Feb 12, 2026
| def __dir__(self): return list(self.tbl.cols) | ||
| def __repr__(self): return ", ".join(dir(self)) | ||
| def __call__(self): return [_Col(self.tbl.name,o.name) for o in self.tbl.columns] | ||
| def __call__(self): return [_Col(self.tbl.name, c) for c in self.tbl.cols] |
Author
There was a problem hiding this comment.
Bugfix. .columns returns a dict. cols returns a list of the names.
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.
Changes
Database.transaction()context manager — acquires a single connection from the pool, starts a transaction, and uses acontextvars.ContextVarto route all queries through it. Existing code (db.t.table.insert(...),db.q(...), etc.) automatically participates in the transaction with no changes needed.Fix
_ColsGetter.__call__— was referencingself.tbl.columnswhich doesn't exist onTable. Changed toself.tbl.cols.Usage
How it works
A
contextvars.ContextVar(_txn_conn) holds the active transaction connection.Database.__getattr__checks it before falling back toself.conn:This means zero changes to calling code — everything just works inside an
async with db.transaction()block.Tests