fix: make get_current_schema async to fix schema.table() alter migrations - #56
Merged
Merged
Conversation
…ions get_current_schema() in all platform files called connection.query(sql, ()) but Connection.query() takes no arguments — it returns a QueryBuilder factory. Migrations using `async with await self.schema.table(...)` would fail with TypeError: Connection.query() takes 1 positional argument but 3 were given. Fix: make get_current_schema async and use await connection.select(sql, ()) instead. Move the schema fetch into Blueprint.__aexit__ so it runs async before to_sql() compiles the ALTER statements. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Schema._type_hints_map was referenced in all three platform get_current_schema methods but was never ported from the backup version of Schema. Add it back so ALTER TABLE migrations can correctly map database column types to Python types. Also add an alter migration fixture (add_body_to_posts_table) to exercise the schema.table() path in the migrate command integration tests. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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
get_current_schema()inPostgresPlatform,MySQLPlatform, andSQLitePlatformwas callingconnection.query(sql, ()), butConnection.query()takes no arguments — it's a factory that returns aQueryBuilderasync with await self.schema.table(...)to alter an existing table would crash withTypeError: Connection.query() takes 1 positional argument but 3 were givenget_current_schemaasyncand usingawait connection.select(sql, ())insteadBlueprint.__aexit__so it runs asynchronously beforeto_sql()compiles the ALTER statementsconn.query = MagicMock(return_value=[])toconn.select = AsyncMock(return_value=[])test_add_nullable_columns_without_from_tablethat reproduces the exact migration pattern that was failingReproduction
Running this migration would raise:
Test plan
uv run pytest fastapi_startkit/tests/masoniteorm/sqlite/schema/test_sqlite_schema_builder_alter.py -v— all 14 tests pass including new regression test🤖 Generated with Claude Code