crate / crash

Crash is an interactive CrateDB command line interface (CLI) SQL shell with autocompletion.
Apache License 2.0
48 stars 13 forks source link

A DuplicateKeyException causes crash to exit #438

Closed romseygeek closed 6 months ago

romseygeek commented 6 months ago

This works correctly in version 0.30.0 but fails with a stack trace and exits the process on version 0.30.2:

cr> drop table doc.test;
DROP OK, 1 row affected (0.050 sec)
cr> create table doc.test (id text primary key, name text);
CREATE OK, 1 row affected (0.322 sec)
cr> insert into doc.test (id, name) values ('1', 'fred')
INSERT OK, 1 row affected (0.014 sec)
cr> insert into doc.test (id, name) values ('1', 'smith');
Traceback (most recent call last):
  File "/Users/romseygeek/Library/Python/3.9/lib/python/site-packages/crate/client/http.py", line 199, in _raise_for_status
    return _raise_for_status_real(response)
  File "/Users/romseygeek/Library/Python/3.9/lib/python/site-packages/crate/client/http.py", line 228, in _raise_for_status_real
    raise ProgrammingError(error.get('message', ''),
crate.client.exceptions.ProgrammingError: DuplicateKeyException[A document with the same primary key exists already]

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/romseygeek/Library/Python/3.9/bin/crash", line 8, in <module>
    sys.exit(main())
  File "/Users/romseygeek/Library/Python/3.9/lib/python/site-packages/crate/crash/command.py", line 617, in main
    loop(cmd, args.history)
  File "/Users/romseygeek/Library/Python/3.9/lib/python/site-packages/crate/crash/repl.py", line 328, in loop
    cmd.process(text)
  File "/Users/romseygeek/Library/Python/3.9/lib/python/site-packages/crate/crash/command.py", line 258, in process
    self._process_lines(text.split('\n'))
  File "/Users/romseygeek/Library/Python/3.9/lib/python/site-packages/crate/crash/command.py", line 270, in _process_lines
    self._process_sql('\n'.join(sql_lines))
  File "/Users/romseygeek/Library/Python/3.9/lib/python/site-packages/crate/crash/command.py", line 275, in _process_sql
    self._exec_and_print(statement)
  File "/Users/romseygeek/Library/Python/3.9/lib/python/site-packages/crate/crash/command.py", line 459, in _exec_and_print
    success = self._exec(statement)
  File "/Users/romseygeek/Library/Python/3.9/lib/python/site-packages/crate/crash/command.py", line 444, in _exec
    self.cursor.execute(statement)
  File "/Users/romseygeek/Library/Python/3.9/lib/python/site-packages/crate/client/cursor.py", line 58, in execute
    self._result = self.connection.client.sql(sql, parameters,
  File "/Users/romseygeek/Library/Python/3.9/lib/python/site-packages/crate/client/http.py", line 454, in sql
    content = self._json_request('POST', self.path, data=data)
  File "/Users/romseygeek/Library/Python/3.9/lib/python/site-packages/crate/client/http.py", line 581, in _json_request
    _raise_for_status(response)
  File "/Users/romseygeek/Library/Python/3.9/lib/python/site-packages/crate/client/http.py", line 202, in _raise_for_status
    raise IntegrityError(ex.message, error_trace=ex.error_trace) from ex
crate.client.exceptions.IntegrityError: DuplicateKeyException[A document with the same primary key exists already]
proddata commented 6 months ago

Maybe related to crate-python 0.34 release

DBAPI: Properly raise IntegrityError exceptions instead of ProgrammingError, when CrateDB raises a DuplicateKeyException.

as it worked for me with crash==0.30.0 and crate-python==0.33.0

https://github.com/crate/crate-python/pull/583/files

amotl commented 6 months ago

Thanks for your reports. GH-439 may have a fix.