Skip to content

Commit 7ec2767

Browse files
author
maxime.c
committed
monkey patch SQLiteDict in order to fix sqlite3.InterfaceError
1 parent f525803 commit 7ec2767

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

airbyte_cdk/sources/streams/http/http_client.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import logging
66
import os
7+
import sqlite3
78
import urllib
89
from pathlib import Path
910
from typing import Any, Callable, Dict, List, Mapping, Optional, Tuple, Union
@@ -56,6 +57,27 @@
5657
BODY_REQUEST_METHODS = ("GET", "POST", "PUT", "PATCH")
5758

5859

60+
def monkey_patched_get_item(self, key):
61+
"""
62+
con.execute can lead to `sqlite3.InterfaceError: bad parameter or other API misuse`. There was a fix implemented
63+
[here](https://github.com/requests-cache/requests-cache/commit/5ca6b9cdcb2797dd2fed485872110ccd72aee55d#diff-f43db4a5edf931647c32dec28ea7557aae4cae8444af4b26c8ecbe88d8c925aaL330-R332)
64+
but there is still no official releases of requests_cache that this is part of. Hence, we will monkeypatch it for now.
65+
"""
66+
with self.connection() as con:
67+
# Using placeholders here with python 3.12+ and concurrency results in the error:
68+
# sqlite3.InterfaceError: bad parameter or other API misuse
69+
cur = con.execute(f"SELECT value FROM {self.table_name} WHERE key='{key}'")
70+
row = cur.fetchone()
71+
cur.close()
72+
if not row:
73+
raise KeyError(key)
74+
75+
return self.deserialize(key, row[0])
76+
77+
78+
requests_cache.SQLiteDict.__getitem__ = monkey_patched_get_item
79+
80+
5981
class MessageRepresentationAirbyteTracedErrors(AirbyteTracedException):
6082
"""
6183
Before the migration to the HttpClient in low-code, the exception raised was

0 commit comments

Comments
 (0)