Closed zevaverbach closed 3 years ago
Hey, @zevaverbach It looks like you are using our SQLAlchemy library https://github.com/snowflakedb/snowflake-sqlalchemy Please note that SQLAlchemy wraps the exceptions raised by the underlying connectors in its own Exception. See for an example: https://github.com/snowflakedb/snowflake-sqlalchemy/blob/6615f51444c539d56ade2be08c542dd4827a70a8/snowdialect.py#L344
@sfc-gh-mkeller thanks for your response, this was spot-on. In your opinion is it problematic that the exception doesn't identify its wrapper (it shows as snowflake.connector.errors.ProgrammingError
as seen in the log)? If so, can you help me understand where/how this is happening? Maybe I can make a PR to fix it (here or in snowflake-sqlalchemy
).
Since I just found my way back here via a Google search, I'm going to explicitly add the solution here.
Instead of using
from snowflake.connector.errors import ProgrammingError
...
except SnowflakeProgrammingError:
....
you need to do
from sqlalchemy import exc as sa_exc
...
except sa_exc.ProgrammingError:
...
Will this be handled in the future? Kind of unintuitive. Encountered this problem today too.
@sfc-gh-mkeller hey, do you have any thoughts about my question above? I've just arrived here for the third time from a Google search, and it seems like a few other wanderers have had the same confusion.
Please answer these questions before submitting your issue. Thanks!
What version of Python are you using (
python --version
)? 3.6.8What operating system and processor architecture are you using (
python -c 'import platform; print(platform.platform())'
)? Linux-3.10.0-1160.6.1.el7.x86_64-x86_64-with-redhat-7.9-MaipoWhat are the component versions in the environment (
pip freeze
)?... for view in views: try: e.execute(f"select * from {view} limit 1") except ProgrammingError as e: print(str(e)) missing_views.append(view) except Exception as e: print(str(e)) continue
... [2020-12-17 14:41:58,078] {connection.py:846} DEBUG - sql=[ROLLBACK], sequence_id=[295], is_file_transfer=[None] [2020-12-17 14:41:58,078] {network.py:940} DEBUG - Active requests sessions: 1, idle: 0 [2020-12-17 14:41:58,078] {network.py:639} DEBUG - remaining request timeout: None, retry cnt: 1 [2020-12-17 14:41:58,078] {network.py:778} DEBUG - socket timeout: 60 [2020-12-17 14:41:58,396] {connectionpool.py:383} DEBUG - "POST /queries/v1/query-request?requestId=&request_guid=HTTP/1.1" 200 995
[2020-12-17 14:41:58,396] {network.py:808} DEBUG - SUCCESS
[2020-12-17 14:41:58,397] {network.py:953} DEBUG - Active requests sessions: 0, idle: 1
[2020-12-17 14:41:58,397] {network.py:536} DEBUG - ret[code] = None, after post request
[2020-12-17 14:41:58,397] {cursor.py:526} DEBUG - sfqid:
[2020-12-17 14:41:58,397] {cursor.py:528} INFO - query execution done
[2020-12-17 14:41:58,397] {cursor.py:530} DEBUG - SUCCESS
[2020-12-17 14:41:58,397] {cursor.py:534} DEBUG - PUT OR GET: None
(snowflake.connector.errors.ProgrammingError) 002057 (42601):: SQL compilation error:
View definition for '' declared X column(s), but view query produces Y column(s).
[SQL: select * from limit 1]
(Background on this error at: http://sqlalche.me/e/f405)
[2020-12-17 14:41:58,398] {connection.py:561} DEBUG - cursor [2020-12-17 14:41:58,398] {cursor.py:443} DEBUG - executing SQL/command [2020-12-17 14:41:58,398] {connection.py:1039} DEBUG - parameters: {} [2020-12-17 14:41:58,398] {cursor.py:466} DEBUG - binding: [select from limit 1] with input=[{}], processed=[{}]
[2020-12-17 14:41:58,398] {cursor.py:502} INFO - query: [select from limit 1]
[2020-12-17 14:41:58,398] {connection.py:1068} DEBUG - sequence counter: 296
[2020-12-17 14:41:58,398] {cursor.py:323} DEBUG - running query [select * from limit 1]
[2020-12-17 14:41:58,399] {cursor.py:332} DEBUG - is_file_transfer: False
...