You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When trying to get the oid for an external table, the query is producing an error rather than returning None. This breaks the metadata reflection for Apache Superset, preventing the creation of physical datasets.
How to reproduce the bug
Create a datashare between two Redshift tenants.
Create an external schema in the consumer tenant.
Use the get_table_oid method for one of the external tables. Below script can be used for testing:
fromsqlalchemyimportcreate_enginefromsqlalchemy_redshift.dialectimportRedshiftDialectREDSHIFT_URI='redshift+psycopg2://user:password@host:port/database'engine=create_engine(REDSHIFT_URI)
withengine.connect() asconnection:
dialect=RedshiftDialect()
try:
table_oid=dialect.get_table_oid(connection, "source_data", schema="test_schema")
exceptExceptionase:
print("An error occurred while retrieving the table OID:")
print(e)
Expected Results
According to the method definition (listed below), it should return None for external tables:
@reflection.cachedefget_table_oid(self, connection, table_name, schema=None, **kw):
"""Fetch the oid for schema.table_name. Return null if not found (external table does not have table oid)"""schema_field='"{schema}".'.format(schema=schema) ifschemaelse""result=connection.execute(
sa.text(
""" select '{schema_field}"{table_name}"'::regclass::oid; """.format(
schema_field=schema_field,
table_name=table_name
)
)
)
returnresult.scalar()
Actual Results
An error is raised. When running sqlalchemy-redshift with psycopg2:
An error occurred while retrieving the table OID:
(psycopg2.errors.FeatureNotSupported) Operation not supported on external tables
[SQL:
select '"test_schema"."source_data"'::regclass::oid;
]
(Background on this error at: https://sqlalche.me/e/14/tw8g)
With redshift-connector:
An error occurred while retrieving the table OID:
(redshift_connector.error.ProgrammingError) {'S': 'ERROR', 'C': '0A000', 'M': 'Operation not supported on external tables', 'F': '../src/pg/src/backend/catalog/namespace.c', 'L': '238', 'R': 'LocalRangeVarGetRelid'}
[SQL:
select '"test_schema"."source_data"'::regclass::oid;
]
(Background on this error at: http://sqlalche.me/e/14/f405)
The text was updated successfully, but these errors were encountered:
Vitor-Avila
changed the title
Avoid raising an error when trying to get the oid for an external table
get_table_oid results in an error for external tables
Jun 19, 2024
Summary
When trying to get the
oid
for an external table, the query is producing an error rather than returningNone
. This breaks the metadata reflection for Apache Superset, preventing the creation of physical datasets.How to reproduce the bug
get_table_oid
method for one of the external tables. Below script can be used for testing:Expected Results
According to the method definition (listed below), it should return
None
for external tables:Actual Results
An error is raised. When running
sqlalchemy-redshift
withpsycopg2
:With
redshift-connector
:The text was updated successfully, but these errors were encountered: