Open fredrike opened 1 year ago
I am also experiencing this issue. The suggested patch works for me, for mixed-case, lower-case, and case-insensitive schema names, but should also be applied to SnowflakeDialect.get_sequence_names()
.
I believe this patch would also fix https://github.com/snowflakedb/snowflake-sqlalchemy/issues/276 and https://github.com/snowflakedb/snowflake-sqlalchemy/issues/388.
hi and thank you for submitting this issue and especially for sharing the patch ! i believe it could be caused by the same underlying cause which causes https://github.com/snowflakedb/snowflake-sqlalchemy/issues/388
can this be a possible duplicate ?
This is a duplicate of both https://github.com/snowflakedb/snowflake-sqlalchemy/issues/388 and https://github.com/snowflakedb/snowflake-sqlalchemy/issues/276. We have been using the patch and it is working for us, with the same change applied to get_sequence_names()
:
@reflection.cache
def get_sequence_names(self, connection, schema=None, **kw):
sql_command = "SHOW SEQUENCES {}".format(
f" IN SCHEMA \"{self.denormalize_name(schema)}\"" if schema else "",
)
try:
cursor = connection.execute(text(sql_command))
thank you for confirming it @fordhoka (and also happy to hear you have a working workaround) marking this as closed so the tracking could be focused on the existing tickets
Thanks @sfc-gh-dszmolka. When can we expect this patch to be included in a release?
At this moment, I don't have any estimated timeline attached to this one unfortunately; but will keep the relevant open issues updated
I think the approach of closing issues without a patch is strange. It is much easier to track progress if issues are open until they are fixed.
What is the holdback in fixing this issue, I've already submitted a patch?
only reason for closing this is because this is a duplicate but happy to reopen it.
is there a PR perhaps? if so, that would be more than appreciated and helpful - I can try to get the connector team to review it. if not, that's also not a problem and we'll get there.
there's quite a backlog for us to work through as you probably noticed, but we're now trying to dedicate more resources and love to this repo as well. so hoping that things will get better over time and thank you for bearing with us.
Well, while we are waiting for this to be fixed I'm monkey patching my code. Perhaps it can be useful for others.
import snowflake.sqlalchemy.snowdialect as sd
from sqlalchemy import exc as sa_exc
from sqlalchemy.sql import text
# Patching get_sequence_names method
@sd.reflection.cache
def get_sequence_names_patched(self, connection, schema=None, **kw):
sql_command = "SHOW SEQUENCES {}".format(
f"IN SCHEMA \"{self.denormalize_name(schema)}\"" if schema else ""
)
try:
cursor = connection.execute(text(sql_command))
return [self.normalize_name(row[0]) for row in cursor]
except sa_exc.ProgrammingError as pe:
if pe.orig.errno == 2003:
# Schema does not exist
return []
# Patching _get_table_comment method
def _get_table_comment_patched(self, connection, table_name, schema=None, **kw):
"""
Returns comment of table in a dictionary as described by SQLAlchemy spec.
"""
sql_command = (
"SHOW /* sqlalchemy:_get_table_comment */ "
"TABLES LIKE '{}'{}".format(
table_name,
f" IN SCHEMA \"{self.denormalize_name(schema)}\"" if schema else "",
)
)
cursor = connection.execute(text(sql_command))
return cursor.fetchone()
# Patching _get_view_comment method
def _get_view_comment_patched(self, connection, table_name, schema=None, **kw):
"""
Returns comment of view in a dictionary as described by SQLAlchemy spec.
"""
sql_command = (
"SHOW /* sqlalchemy:_get_view_comment */ "
"VIEWS LIKE '{}'{}".format(
table_name,
f" IN SCHEMA \"{self.denormalize_name(schema)}\"" if schema else "",
)
)
cursor = connection.execute(text(sql_command))
return cursor.fetchone()
# Apply patches by replacing the original methods
sd.SnowflakeDialect.get_sequence_names = get_sequence_names_patched
sd.SnowflakeDialect._get_table_comment = _get_table_comment_patched
sd.SnowflakeDialect._get_view_comment = _get_view_comment_patched
Please answer these questions before submitting your issue. Thanks!
What version of Python are you using?
What operating system and processor architecture are you using?
Linux-5.4.0-1074-azure-x86_64-with-glibc2.17
What are the component versions in the environment (
pip freeze
)?What did you do?
What did you expect to see?
The tables containing
control
should be listed. Instead i get this error:Can you set logging to DEBUG and collect the logs?
Better, I have a suggested patch:
So, qoute the schema name seems to do the trick.