Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separate SQL errors from connection errors during query execution #74

Closed
yzchang opened this issue Oct 5, 2020 · 5 comments
Closed
Assignees
Milestone

Comments

@yzchang
Copy link
Member

yzchang commented Oct 5, 2020

Currently, when something (anything?) went wrong during a query execution, the user gets an OperationalError. For instance,

>>> c = pymonetdb.connect("demo", host="localhost", port=50000)
>>> cc = c.cursor()
>>> c.set_autocommit(True)
>>> cc.execute("select * from sys.tables t1, sys.tables t2, sys.tables t3")

# I killed the server during the execution of this query!

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/kutsurak/.cache/pypoetry/virtualenvs/test-pymonetdb-_ivNU08G-py3.8/lib/python3.8/site-packages/pymonetdb/sql/cursors.py", line 165, in execute
    block = self.connection.execute(query)
  File "/home/kutsurak/.cache/pypoetry/virtualenvs/test-pymonetdb-_ivNU08G-py3.8/lib/python3.8/site-packages/pymonetdb/sql/connections.py", line 140, in execute
    return self.command('s' + query + '\n;')
  File "/home/kutsurak/.cache/pypoetry/virtualenvs/test-pymonetdb-_ivNU08G-py3.8/lib/python3.8/site-packages/pymonetdb/sql/connections.py", line 145, in command
    return self.mapi.cmd(command)
  File "/home/kutsurak/.cache/pypoetry/virtualenvs/test-pymonetdb-_ivNU08G-py3.8/lib/python3.8/site-packages/pymonetdb/mapi.py", line 240, in cmd
    response = self._getblock()
  File "/home/kutsurak/.cache/pypoetry/virtualenvs/test-pymonetdb-_ivNU08G-py3.8/lib/python3.8/site-packages/pymonetdb/mapi.py", line 317, in _getblock
    return self._getblock_inet()
  File "/home/kutsurak/.cache/pypoetry/virtualenvs/test-pymonetdb-_ivNU08G-py3.8/lib/python3.8/site-packages/pymonetdb/mapi.py", line 323, in _getblock_inet
    flag = self._getbytes(2)
  File "/home/kutsurak/.cache/pypoetry/virtualenvs/test-pymonetdb-_ivNU08G-py3.8/lib/python3.8/site-packages/pymonetdb/mapi.py", line 347, in _getbytes
    raise OperationalError("Server closed connection")
pymonetdb.exceptions.OperationalError: Server closed connection

Would it be possible to separate SQL errors from other errors, in particular, connection errors? In that way, it would be much easier for the users to capture and deal with the query exeuction errors differently than all other types of errors.

@gijzelaerr
Copy link
Collaborator

yes, thats possible. What Exception do you think would match this case?

@gijzelaerr gijzelaerr self-assigned this Oct 5, 2020
@gijzelaerr gijzelaerr added this to the 1.4.0 milestone Oct 5, 2020
@yzchang
Copy link
Member Author

yzchang commented Oct 5, 2020

Great. I don't know if there are other types of errors next to SQL errors and connection errors. But for this particular example, when something went wrong with the connection during a query execution, it would be handy to have something like a ConnectionError. Does Python have something standard defined for this?

@gijzelaerr
Copy link
Collaborator

@yzchang
Copy link
Member Author

yzchang commented Oct 5, 2020

Yes, that'll work. Not sure if you want to give even more detail. Does a BrokenPipeError or a ConnectionResetError apply here? But a ConnectionError is good enough for me.

gijzelaerr added a commit that referenced this issue Nov 1, 2020
* slight modernisation

* switch to github actions

* add github actions

* add github actions

* Fix style errors

* fix issue #74

* fix issue #75

* fix issue #71

* Disable pypy testing

* add wheel target

* Disable pypy testing

Co-authored-by: Gijs Molenaar <gijs.molenaar@dpgmedia.nl>
@gijzelaerr
Copy link
Collaborator

Fixed in master and 1.4.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants