Skip to content

Commit 0328cb8

Browse files
authored
Merge pull request #22 from ydb-platform/fix_pending_query
Fix pending query issue
2 parents d4c5a28 + 56d4151 commit 0328cb8

File tree

4 files changed

+152
-151
lines changed

4 files changed

+152
-151
lines changed

tests/test_connections.py

Lines changed: 57 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,11 @@ def _test_isolation_level_read_only(
2929
cursor = connection.cursor()
3030
with suppress(dbapi.DatabaseError):
3131
maybe_await(cursor.execute_scheme("DROP TABLE foo"))
32-
maybe_await(cursor.execute_scheme(
33-
"CREATE TABLE foo(id Int64 NOT NULL, PRIMARY KEY (id))"
34-
))
32+
maybe_await(
33+
cursor.execute_scheme(
34+
"CREATE TABLE foo(id Int64 NOT NULL, PRIMARY KEY (id))"
35+
)
36+
)
3537

3638
connection.set_isolation_level(isolation_level)
3739
cursor = connection.cursor()
@@ -60,9 +62,11 @@ def _test_connection(self, connection: dbapi.Connection) -> None:
6062
with pytest.raises(dbapi.ProgrammingError):
6163
maybe_await(connection.describe("/local/foo"))
6264

63-
maybe_await(cur.execute_scheme(
64-
"CREATE TABLE foo(id Int64 NOT NULL, PRIMARY KEY (id))"
65-
))
65+
maybe_await(
66+
cur.execute_scheme(
67+
"CREATE TABLE foo(id Int64 NOT NULL, PRIMARY KEY (id))"
68+
)
69+
)
6670

6771
assert maybe_await(connection.check_exists("/local/foo"))
6872

@@ -84,26 +88,28 @@ def _test_cursor_raw_query(self, connection: dbapi.Connection) -> None:
8488
"CREATE TABLE test(id Int64 NOT NULL, text Utf8, PRIMARY KEY (id))"
8589
))
8690

87-
maybe_await(cur.execute(
88-
"""
91+
maybe_await(
92+
cur.execute(
93+
"""
8994
DECLARE $data AS List<Struct<id:Int64, text: Utf8>>;
9095
9196
INSERT INTO test SELECT id, text FROM AS_TABLE($data);
9297
""",
93-
{
94-
"$data": ydb.TypedValue(
95-
[
96-
{"id": 17, "text": "seventeen"},
97-
{"id": 21, "text": "twenty one"},
98-
],
99-
ydb.ListType(
100-
ydb.StructType()
101-
.add_member("id", ydb.PrimitiveType.Int64)
102-
.add_member("text", ydb.PrimitiveType.Utf8)
103-
),
104-
)
105-
},
106-
))
98+
{
99+
"$data": ydb.TypedValue(
100+
[
101+
{"id": 17, "text": "seventeen"},
102+
{"id": 21, "text": "twenty one"},
103+
],
104+
ydb.ListType(
105+
ydb.StructType()
106+
.add_member("id", ydb.PrimitiveType.Int64)
107+
.add_member("text", ydb.PrimitiveType.Utf8)
108+
),
109+
)
110+
},
111+
)
112+
)
107113

108114
maybe_await(cur.execute_scheme("DROP TABLE test"))
109115

@@ -112,13 +118,15 @@ def _test_cursor_raw_query(self, connection: dbapi.Connection) -> None:
112118
def _test_errors(
113119
self,
114120
connection: dbapi.Connection,
115-
connect_method: callable = dbapi.connect
121+
connect_method: callable = dbapi.connect,
116122
) -> None:
117123
with pytest.raises(dbapi.InterfaceError):
118-
maybe_await(connect_method(
119-
"localhost:2136", # type: ignore
120-
database="/local666", # type: ignore
121-
))
124+
maybe_await(
125+
connect_method(
126+
"localhost:2136", # type: ignore
127+
database="/local666", # type: ignore
128+
)
129+
)
122130

123131
cur = connection.cursor()
124132

@@ -137,9 +145,9 @@ def _test_errors(
137145
with pytest.raises(dbapi.ProgrammingError):
138146
maybe_await(cur.execute("SELECT * FROM test"))
139147

140-
maybe_await(cur.execute_scheme(
141-
"CREATE TABLE test(id Int64, PRIMARY KEY (id))"
142-
))
148+
maybe_await(
149+
cur.execute_scheme("CREATE TABLE test(id Int64, PRIMARY KEY (id))")
150+
)
143151

144152
maybe_await(cur.execute("INSERT INTO test(id) VALUES(1)"))
145153

@@ -154,8 +162,9 @@ def _test_bulk_upsert(self, connection: dbapi.Connection) -> None:
154162
with suppress(dbapi.DatabaseError):
155163
maybe_await(cursor.execute_scheme("DROP TABLE pet"))
156164

157-
maybe_await(cursor.execute_scheme(
158-
"""
165+
maybe_await(
166+
cursor.execute_scheme(
167+
"""
159168
CREATE TABLE pet (
160169
pet_id INT,
161170
name TEXT NOT NULL,
@@ -165,7 +174,8 @@ def _test_bulk_upsert(self, connection: dbapi.Connection) -> None:
165174
PRIMARY KEY (pet_id)
166175
);
167176
"""
168-
))
177+
)
178+
)
169179

170180
column_types = (
171181
ydb.BulkUpsertColumns()
@@ -182,14 +192,14 @@ def _test_bulk_upsert(self, connection: dbapi.Connection) -> None:
182192
"name": "Lester",
183193
"pet_type": "Hamster",
184194
"birth_date": "2020-06-23",
185-
"owner": "Lily"
195+
"owner": "Lily",
186196
},
187197
{
188198
"pet_id": 4,
189199
"name": "Quincy",
190200
"pet_type": "Parrot",
191201
"birth_date": "2013-08-11",
192-
"owner": "Anne"
202+
"owner": "Anne",
193203
},
194204
]
195205

@@ -204,18 +214,19 @@ def _test_error_with_interactive_tx(
204214
self,
205215
connection: dbapi.Connection,
206216
) -> None:
207-
208217
cur = connection.cursor()
209-
maybe_await(cur.execute_scheme(
210-
"""
218+
maybe_await(
219+
cur.execute_scheme(
220+
"""
211221
DROP TABLE IF EXISTS test;
212222
CREATE TABLE test (
213223
id Int64 NOT NULL,
214224
val Int64,
215225
PRIMARY KEY(id)
216226
)
217227
"""
218-
))
228+
)
229+
)
219230

220231
connection.set_isolation_level(dbapi.IsolationLevel.SERIALIZABLE)
221232
maybe_await(connection.begin())
@@ -274,8 +285,8 @@ def test_bulk_upsert(self, connection: dbapi.Connection) -> None:
274285
self._test_bulk_upsert(connection)
275286

276287
def test_errors_with_interactive_tx(
277-
self, connection: dbapi.Connection
278-
) -> None:
288+
self, connection: dbapi.Connection
289+
) -> None:
279290
self._test_error_with_interactive_tx(connection)
280291

281292

@@ -291,8 +302,10 @@ def connect() -> dbapi.AsyncConnection:
291302
try:
292303
yield conn
293304
finally:
305+
294306
def close() -> None:
295307
maybe_await(conn.close())
308+
296309
await greenlet_spawn(close)
297310

298311
@pytest.mark.asyncio
@@ -315,7 +328,9 @@ async def test_isolation_level_read_only(
315328
) -> None:
316329
await greenlet_spawn(
317330
self._test_isolation_level_read_only,
318-
connection, isolation_level, read_only
331+
connection,
332+
isolation_level,
333+
read_only,
319334
)
320335

321336
@pytest.mark.asyncio

tests/test_cursors.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,6 @@ class TestCursor(BaseCursorTestSuit):
161161
def sync_cursor(
162162
self, session_pool_sync: ydb.QuerySessionPool
163163
) -> Generator[Cursor]:
164-
165164
cursor = Cursor(
166165
FakeSyncConnection(),
167166
session_pool_sync,
@@ -195,9 +194,7 @@ def test_cursor_fetch_all_multiple_result_sets(
195194
) -> None:
196195
self._test_cursor_fetch_all_multiple_result_sets(sync_cursor)
197196

198-
def test_cursor_state_after_error(
199-
self, sync_cursor: Cursor
200-
) -> None:
197+
def test_cursor_state_after_error(self, sync_cursor: Cursor) -> None:
201198
self._test_cursor_state_after_error(sync_cursor)
202199

203200

@@ -255,6 +252,4 @@ async def test_cursor_fetch_all_multiple_result_sets(
255252
async def test_cursor_state_after_error(
256253
self, async_cursor: AsyncCursor
257254
) -> None:
258-
await greenlet_spawn(
259-
self._test_cursor_state_after_error, async_cursor
260-
)
255+
await greenlet_spawn(self._test_cursor_state_after_error, async_cursor)

ydb_dbapi/connections.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,9 @@ def __init__(
102102
database=self.database,
103103
credentials=self.credentials,
104104
query_client_settings=self._get_client_settings(),
105-
root_certificates=ydb.load_ydb_root_certificate(root_certificates_path),
105+
root_certificates=ydb.load_ydb_root_certificate(
106+
root_certificates_path
107+
),
106108
)
107109
self._driver = self._driver_cls(driver_config)
108110
self._session_pool = self._pool_cls(self._driver, size=5)

0 commit comments

Comments
 (0)