Migrated from: MasoniteFramework/orm#954
Original author: @elgow
Originally opened: 2026-01-05
Original state: closed
Describe the bug
When a QueryBuilder instance is used to execute a query the _bindings and _columns attributes are set to those of the query. If the instance is set to point to another table using table() the original _bindings and _columns remain in place. In general this will cause an error because the new table does not contain the columns of the original table. The original query cannot be expected to be valid against a different table, so the table() method should reset the state.
To Reproduce
resolver = ConnectionResolver(connection_details=DATABASE)
connection = resolver.connection_factory.make("postgres")
builder = QueryBuilder(connection_details=DATABASE, connection_class=connection)
columns_query = builder.table("information_schema.columns").select('column_name').where('table_name', '=', 'some_table')
columns = [x['column_name'] for x in columns_query.get()]
builder.reset()
query = builder.table('some_other_table').select("not_column_name")
query.get()
The result of the second query.get() will be an error due to the 'column_name' column being missing on "some_other_table".
Expected behavior
The new query on the new table should be executed without mixing in the original query. This should be the case even without the reset() call.
Desktop (please complete the following information):
OS: Mac M2
Version Sequoia 15.5
What database are you using?
Type: Postgres
Version 15.6 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 8.5.0 20210514 (Red Hat 8.5.0-20), 64-bit
Masonite ORM 3.0.0
Additional context
Any other steps you are doing or any other related information that will help us debug the problem please put here.
Describe the bug
When a QueryBuilder instance is used to execute a query the
_bindingsand_columnsattributes are set to those of the query. If the instance is set to point to another table usingtable()the original_bindingsand_columnsremain in place. In general this will cause an error because the new table does not contain the columns of the original table. The original query cannot be expected to be valid against a different table, so thetable()method should reset the state.To Reproduce
The result of the second
query.get()will be an error due to the 'column_name' column being missing on "some_other_table".Expected behavior
The new query on the new table should be executed without mixing in the original query. This should be the case even without the
reset()call.Desktop (please complete the following information):
OS: Mac M2
Version Sequoia 15.5
What database are you using?
Type: Postgres
Version 15.6 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 8.5.0 20210514 (Red Hat 8.5.0-20), 64-bit
Masonite ORM 3.0.0
Additional context
Any other steps you are doing or any other related information that will help us debug the problem please put here.