diff --git a/airbyte_cdk/sources/streams/http/http_client.py b/airbyte_cdk/sources/streams/http/http_client.py index ff3c8e733..63c451c49 100644 --- a/airbyte_cdk/sources/streams/http/http_client.py +++ b/airbyte_cdk/sources/streams/http/http_client.py @@ -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 diff --git a/unit_tests/test_requests_cache_monkeypatch_version.py b/unit_tests/test_requests_cache_monkeypatch_version.py new file mode 100644 index 000000000..d9c7bc510 --- /dev/null +++ b/unit_tests/test_requests_cache_monkeypatch_version.py @@ -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"