question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

KeyError raised on prepared statement deallocate

See original GitHub issue

Expected behavior

When executing a prepared statement, the statement shall be executed succesfully

Actual behavior

Multipe responses from Trino contain the same deallocate header, although the code only accepts this operation to be executed once.

See https://github.com/trinodb/trino-python-client/blob/f97aea6afb2663f0a29beb6477c18c9d9a88832e/trino/client.py#L610

Steps To Reproduce

I wasn’t able to reproduce this locally, only in CI. So I assume some type of race condition is happening.

Log output

140581443462912: before: {}
140581443462912: after: {"st_ccb622831a2d43dfb03a186180695c1e": "INSERT INTO delta.test16650588382631922575_test_incremental_delete_insert.seed (\"state\", \"county\", \"city\", \"last_visit_date\")\n VALUES \n  ROW (?, ?, ?, ?)\n, ROW (?, ?, ?, ?)\n, ROW (?, ?, ?, ?)\n, ROW (?, ?, ?, ?)\n, ROW (?, ?, ?, ?)\n, ROW (?, ?, ?, ?)\n"}
140581443462912: Deallocating st_ccb622831a2d43dfb03a186180695c1e
140581443462912: before: {"st_ccb622831a2d43dfb03a186180695c1e": "INSERT INTO delta.test16650588382631922575_test_incremental_delete_insert.seed (\"state\", \"county\", \"city\", \"last_visit_date\")\n VALUES \n  ROW (?, ?, ?, ?)\n, ROW (?, ?, ?, ?)\n, ROW (?, ?, ?, ?)\n, ROW (?, ?, ?, ?)\n, ROW (?, ?, ?, ?)\n, ROW (?, ?, ?, ?)\n"}
140581443462912http://localhost:8080/v1/statement/executing/20[2210](https://github.com/mdesmet/dbt-trino/actions/runs/3197070204/jobs/5219814756#step:4:2211)06_122055_01035_2z8ej/ye8e084beb54f7dd32c5b3d682239264dbe6a6262/0 : <trino.client.TrinoRequest object at 0x7fdbd40a4b50> : st_ccb622831a2d43dfb03a186180695c1e
140581443462912http://localhost:8080/v1/statement/executing/20221006_122055_01035_2z8ej/y382a838b78d9dcd5df455e0fd1335d282cd7f1a2/1 : <trino.client.TrinoRequest object at 0x7fdbd40a4b50> : st_ccb622831a2d43dfb03a186180695c1e
Error while running:
insert into delta.test16650588382631922575_test_incremental_delete_insert.seed ("state", "county", "city", "last_visit_date") values
          (?,?,?,?),(?,?,?,?),(?,?,?,?),(?,?,?,?),(?,?,?,?),(?,?,?,?)
'st_ccb622831a2d43dfb03a186180695c1e'

Operating System

Ubuntu

Trino Python client version

0.317.0

Trino Server version

398

Python version

3.10.5

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
hashharcommented, Oct 10, 2022

Ah so the JDBC client maintains two sets - one for added and another for deallocated and when making the requests it merges them together. But here in Python client we merge them when processing headers itself (on each next-uri).

So for now we can “fix” the python client by ignoring the deallocation if statement is already removed and follow-up to see if Trino should do things differently or not. If not having two separate sets makes some sense as it’s easier to reason about (and inspect).

0reactions
hashharcommented, Oct 11, 2022

Reopening this to continue discussion.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Postgres is throwing errors about prepared statements
The client that throws the error trying to create prepared statement within the same session over again, that's why it fails. It needs...
Read more >
Changelog — Tortoise ORM v0.17.3 Documentation
Uses prepared statements for insert, large insert performance increase. Pre-generate base pypika query object per model, providing general purpose speedup. 0.10 ...
Read more >
Error Messages - SQLAlchemy 1.4 Documentation
Exception raised when the database encounters an internal error, e.g. the cursor is not valid anymore, the transaction is out of sync, etc....
Read more >
Athena — Boto3 Docs 1.26.37 documentation - Amazon AWS
Returns the details of a single prepared statement or a list of up to 256 prepared statements for the array of prepared statement...
Read more >
mysql-connector-python/connection.py at master - GitHub
Raises AttributeError when a configuration parameter is invalid,. missing or unsupported. ... except KeyError: ... """Deallocate a prepared MySQL statement.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found