Skip to content

Commit

Permalink
fix(mysql): catch PyMySQL OperationalError exception (#7919)
Browse files Browse the repository at this point in the history
## Description of changes

When trying to connect to a mySQL backend, the following error can
appear:

```
OperationalError: (pymysql.err.OperationalError) (1298, "Unknown or incorrect time zone: 'UTC'")
(Background on this error at: https://sqlalche.me/e/20/e3q8)
```

This is due to an exception generated by PyMySQL.
The exception, formerly generated by SQLAlchemy was already caught by
Ibis since #6010, this PR adds a catching of the PyMySQL exception.

## Issues closed
Resolves #7918
  • Loading branch information
maxibor authored Jan 8, 2024
1 parent dc1ffad commit f2c2664
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion ibis/backends/mysql/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import warnings
from typing import TYPE_CHECKING, Literal

import pymysql
import sqlalchemy as sa
from sqlalchemy.dialects import mysql

Expand Down Expand Up @@ -112,7 +113,7 @@ def connect(dbapi_connection, connection_record):
with dbapi_connection.cursor() as cur:
try:
cur.execute("SET @@session.time_zone = 'UTC'")
except sa.exc.OperationalError:
except (sa.exc.OperationalError, pymysql.err.OperationalError):
warnings.warn("Unable to set session timezone to UTC.")

super().do_connect(engine)
Expand Down

0 comments on commit f2c2664

Please sign in to comment.