pudo / dataset

Easy-to-use data handling for SQL data stores with support for implicit table creation, bulk loading, and transactions.
https://dataset.readthedocs.org/
MIT License
4.76k stars 297 forks source link

sqlalchemy.exc.ResourceClosedError: when performing a query #365

Closed rainwala closed 3 years ago

rainwala commented 3 years ago

Hi,

thank you for your work making this great reource. Recently, I have had trouble running the following code after I upgraded my system from Ubuntu 18.04 to 20.04. Previously this code ran fine:

import dataset
db = dataset.connect('mysql+mysqlconnector://user@localhost/covid'
result = db.query("alter table patient auto_increment = 1")

Now I get the error:

Traceback (most recent call last):
  File "clean_db.py", line 12, in <module>
    result = db.query("alter table patient auto_increment = 1")
  File "/usr/local/lib/python3.8/dist-packages/dataset/database.py", line 302, in query
    return ResultIter(rp, row_type=self.row_type, step=_step)
  File "/usr/local/lib/python3.8/dist-packages/dataset/util.py", line 43, in __init__
    self.keys = list(result_proxy.keys())
  File "/usr/local/lib/python3.8/dist-packages/sqlalchemy/engine/result.py", line 700, in keys
    return self._metadata.keys
  File "/usr/local/lib/python3.8/dist-packages/sqlalchemy/engine/cursor.py", line 1201, in keys
    self._we_dont_return_rows()
  File "/usr/local/lib/python3.8/dist-packages/sqlalchemy/engine/cursor.py", line 1178, in _we_dont_return_rows
    util.raise_(
  File "/usr/local/lib/python3.8/dist-packages/sqlalchemy/util/compat.py", line 198, in raise_
    raise exception
sqlalchemy.exc.ResourceClosedError: This result object does not return rows. It has been closed automatically.
TakamasaNiijima-Techoes commented 3 years ago

I have encounter the same issue.

JonasLoos commented 3 years ago

A workaround might be to call the sqlalchemy function db.executable.execute directly:

db = dataset.connect('...')
db.executable.execute('...')