Skip to content

Commit 43c45fb

Browse files
committed
Fix get_table_names() reflection method
It did not respect the `schema` query argument in SQLAlchemy connection URLs.
1 parent 5ddc8e1 commit 43c45fb

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

CHANGES.md

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
- Added support for CrateDB's [FLOAT_VECTOR] data type. For SQLAlchemy
77
column definitions, you can use it like `FloatVector(dimensions=1024)`.
88

9+
- Fixed `get_table_names()` reflection method, it did not respect the
10+
`schema` query argument in SQLAlchemy connection URLs.
11+
912
[FLOAT_VECTOR]: https://crate.io/docs/crate/reference/en/master/general/ddl/data-types.html#float-vector
1013

1114

src/sqlalchemy_cratedb/dialect.py

+11
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,15 @@ def connect(self, host=None, port=None, *args, **kwargs):
229229
def _get_default_schema_name(self, connection):
230230
return 'doc'
231231

232+
def _get_effective_schema_name(self, connection):
233+
schema_name_raw = connection.engine.url.query.get("schema")
234+
schema_name = None
235+
if isinstance(schema_name_raw, str):
236+
schema_name = schema_name_raw
237+
elif isinstance(schema_name_raw, tuple):
238+
schema_name = schema_name_raw[0]
239+
return schema_name
240+
232241
def _get_server_version_info(self, connection):
233242
return tuple(connection.connection.lowest_server_version.version)
234243

@@ -258,6 +267,8 @@ def get_schema_names(self, connection, **kw):
258267

259268
@reflection.cache
260269
def get_table_names(self, connection, schema=None, **kw):
270+
if schema is None:
271+
schema = self._get_effective_schema_name(connection)
261272
cursor = connection.exec_driver_sql(
262273
"SELECT table_name FROM information_schema.tables "
263274
"WHERE {0} = ? "

0 commit comments

Comments
 (0)