Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions airbyte_cdk/sources/streams/http/http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,27 @@
BODY_REQUEST_METHODS = ("GET", "POST", "PUT", "PATCH")


def monkey_patched_get_item(self, key): # type: ignore # this interface is a copy/paste from the requests_cache lib
"""
con.execute can lead to `sqlite3.InterfaceError: bad parameter or other API misuse`. There was a fix implemented
[here](https://github.com/requests-cache/requests-cache/commit/5ca6b9cdcb2797dd2fed485872110ccd72aee55d#diff-f43db4a5edf931647c32dec28ea7557aae4cae8444af4b26c8ecbe88d8c925aaL330-R332)
but there is still no official releases of requests_cache that this is part of. Hence, we will monkeypatch it for now.
"""
with self.connection() as con:
# Using placeholders here with python 3.12+ and concurrency results in the error:
# sqlite3.InterfaceError: bad parameter or other API misuse
cur = con.execute(f"SELECT value FROM {self.table_name} WHERE key='{key}'")
row = cur.fetchone()
cur.close()
if not row:
raise KeyError(key)

return self.deserialize(key, row[0])


requests_cache.SQLiteDict.__getitem__ = monkey_patched_get_item # type: ignore # see the method doc for more information


class MessageRepresentationAirbyteTracedErrors(AirbyteTracedException):
"""
Before the migration to the HttpClient in low-code, the exception raised was
Expand Down
11 changes: 11 additions & 0 deletions unit_tests/test_requests_cache_monkeypatch_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import requests_cache


def test_assert_requests_cache_version():
"""
We need to be alerted once the requests_cache version is updated. The reason is that we monkey patch one of the
method in order to fix a bug until a new version is released.

For more information about the reasons of this test, see monkey_patched_get_item in http_client.py
"""
assert requests_cache.__version__ == "1.2.1"
Loading