-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix get_table_oid in HANAInspector to also work with inspectors creat…
…ed from Engine instances (#242) Similar to the issue for the built-in PostgreSQL dialect resp. the corresponding PGInspector class (sqlalchemy/sqlalchemy#6170) the get_table_oid method of the HANAInspector cannot be used when the inspector was created using the Engine instance and not a Connection instance. This PR fixes this using the same solution from the PGInspector class (see also here for details: https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/2697).
- Loading branch information
1 parent
15798be
commit f4e91bf
Showing
3 changed files
with
55 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
"""SAP HANA Inspector tests.""" | ||
|
||
from __future__ import annotations | ||
|
||
from sqlalchemy import Integer, String, create_engine, inspect | ||
from sqlalchemy.engine import Connection, Engine | ||
from sqlalchemy.testing import config, eq_, is_true | ||
from sqlalchemy.testing.fixtures import TablesTest | ||
from sqlalchemy.testing.schema import Column, Table | ||
|
||
from sqlalchemy_hana.dialect import HANAInspector | ||
|
||
|
||
class InspectorTest(TablesTest): | ||
|
||
@classmethod | ||
def define_tables(cls, metadata): | ||
Table( | ||
"tbl", | ||
metadata, | ||
Column("id", Integer, primary_key=True, autoincrement=True), | ||
Column("desc", String(100)), | ||
) | ||
|
||
def test_get_table_oid(self, connection): | ||
connection_inspector = inspect(connection) | ||
|
||
is_true(isinstance(connection_inspector, HANAInspector)) | ||
is_true(isinstance(connection_inspector.bind, Connection)) | ||
|
||
table_oid1 = connection_inspector.get_table_oid( | ||
self.tables.tbl.name, self.tables.tbl.schema | ||
) | ||
is_true(isinstance(table_oid1, int)) | ||
|
||
eng = create_engine(config.db.url) | ||
eng_inspector = inspect(eng) | ||
|
||
is_true(isinstance(eng_inspector, HANAInspector)) | ||
is_true(isinstance(eng_inspector.bind, Engine)) | ||
|
||
table_oid2 = eng_inspector.get_table_oid( | ||
self.tables.tbl.name, self.tables.tbl.schema | ||
) | ||
is_true(isinstance(table_oid2, int)) | ||
|
||
eq_(table_oid1, table_oid2) |