From 7ec2767601dbc50f032523d09dd26ec7f368c587 Mon Sep 17 00:00:00 2001 From: "maxime.c" Date: Tue, 26 Aug 2025 08:05:11 -0400 Subject: [PATCH 1/3] monkey patch SQLiteDict in order to fix sqlite3.InterfaceError --- .../sources/streams/http/http_client.py | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/airbyte_cdk/sources/streams/http/http_client.py b/airbyte_cdk/sources/streams/http/http_client.py index ff3c8e733..49392f346 100644 --- a/airbyte_cdk/sources/streams/http/http_client.py +++ b/airbyte_cdk/sources/streams/http/http_client.py @@ -4,6 +4,7 @@ import logging import os +import sqlite3 import urllib from pathlib import Path from typing import Any, Callable, Dict, List, Mapping, Optional, Tuple, Union @@ -56,6 +57,27 @@ BODY_REQUEST_METHODS = ("GET", "POST", "PUT", "PATCH") +def monkey_patched_get_item(self, key): + """ + 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 + + class MessageRepresentationAirbyteTracedErrors(AirbyteTracedException): """ Before the migration to the HttpClient in low-code, the exception raised was From 07f1ce3268111bbc69de5941b6e8918b18eab479 Mon Sep 17 00:00:00 2001 From: "maxime.c" Date: Tue, 26 Aug 2025 10:42:38 -0400 Subject: [PATCH 2/3] add test to validate lib version --- airbyte_cdk/sources/streams/http/http_client.py | 1 - unit_tests/test_requests_cache_monkeypatch_version.py | 11 +++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 unit_tests/test_requests_cache_monkeypatch_version.py diff --git a/airbyte_cdk/sources/streams/http/http_client.py b/airbyte_cdk/sources/streams/http/http_client.py index 49392f346..0b4210535 100644 --- a/airbyte_cdk/sources/streams/http/http_client.py +++ b/airbyte_cdk/sources/streams/http/http_client.py @@ -4,7 +4,6 @@ import logging import os -import sqlite3 import urllib from pathlib import Path from typing import Any, Callable, Dict, List, Mapping, Optional, Tuple, Union 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" From e358cce13b337e549e016020b14a1d9170778ad6 Mon Sep 17 00:00:00 2001 From: "maxime.c" Date: Tue, 26 Aug 2025 10:50:07 -0400 Subject: [PATCH 3/3] fix mypy --- airbyte_cdk/sources/streams/http/http_client.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/airbyte_cdk/sources/streams/http/http_client.py b/airbyte_cdk/sources/streams/http/http_client.py index 0b4210535..63c451c49 100644 --- a/airbyte_cdk/sources/streams/http/http_client.py +++ b/airbyte_cdk/sources/streams/http/http_client.py @@ -56,7 +56,7 @@ BODY_REQUEST_METHODS = ("GET", "POST", "PUT", "PATCH") -def monkey_patched_get_item(self, key): +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) @@ -74,7 +74,7 @@ def monkey_patched_get_item(self, key): return self.deserialize(key, row[0]) -requests_cache.SQLiteDict.__getitem__ = monkey_patched_get_item +requests_cache.SQLiteDict.__getitem__ = monkey_patched_get_item # type: ignore # see the method doc for more information class MessageRepresentationAirbyteTracedErrors(AirbyteTracedException):