Read the default schema from the server with the ibm_db driver - #203
Open
aminghadersohi wants to merge 1 commit into
Open
aminghadersohi wants to merge 1 commit into
aminghadersohi wants to merge 1 commit into
Conversation
_get_default_schema_name used ibm_db_dbi's get_current_schema(), which falls back to the user argument passed to connect(). create_connect_args now puts the credentials in the DSN and passes an empty user, so the default schema became '' and reflection without an explicit schema found no tables or columns. Query VALUES CURRENT SCHEMA instead, which reports the session's actual current schema regardless of how the connection was made. Signed-off-by: Amin Ghadersohi <amin.ghadersohi@gmail.com>
This was referenced Sep 26, 2026
This branch has not been deployed
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
On current master,
DB2Dialect_ibm_db.default_schema_nameis''for ordinary host/port URLs. As a result, reflection calls without an explicit schema (inspect(conn).get_table_names(),get_columns(table),Table(..., autoload_with=conn)) find nothing._get_default_schema_namecalls ibm_db_dbi'sget_current_schema(). That returnsSQL_ATTR_CURRENT_SCHEMAonly when it was set explicitly; otherwise it falls back to theuserargument passed toconnect(). Since thecreate_connect_argsrefactor (#199), credentials go in the DSN anduseris passed as"", so the fallback, and therefore the default schema, is empty. Released 0.4.4 is unaffected.Fix
Ask the server with
VALUES CURRENT SCHEMA, which reports the session's actual current schema however the connection was made (DSN credentials,CURRENTSCHEMA, or a laterSET SCHEMA). It usesexec_driver_sqlon SQLAlchemy 1.4+ andexecuteon older versions. The query runs once, at dialect initialization.Tests
test/test_default_schema.py:''.default_schema_namematchesVALUES CURRENT SCHEMA, and a table created without a schema is found byget_table_names()andget_columns()without a schema argument.Same test file, Python 3.11, SQLAlchemy 2.0.52, ibm-db 3.2.3, local throwaway DB2 Community Edition 11.5.9.0; only
ibm_db_sa/ibm_db.pydiffers from master7f3866e:'' != 'db2inst1', table not found)The connectionless test also passes on SQLAlchemy 1.4.54. Ruff 0.5.0 check/format on the new test and
git diff --checkpass.test/test_out_parameters.pyerrors identically before and after (it callsEngine.execute, removed in SQLAlchemy 2.0). The full legacy suite was not run.