6
0
mirror of https://github.com/FirebirdSQL/firebird-qa.git synced 2025-01-22 13:33:07 +01:00

Added/Updated tests\bugs\gh_8115_test.py: Resultset of cursor that executes using instance of selectable PreparedStatement must be stored in some variable in order to have ability close it EXPLICITLY, before PS will be freed. Otherwise access violation can raises when Python runs garbage collection.

This commit is contained in:
pavel-zotov 2025-01-18 14:58:29 +03:00
parent df454c615b
commit b480a3fe43

View File

@ -14,6 +14,13 @@ NOTES:
https://github.com/FirebirdSQL/firebird/commit/bbd35ab07c129e9735f081fcd29172a8187aa8ab https://github.com/FirebirdSQL/firebird/commit/bbd35ab07c129e9735f081fcd29172a8187aa8ab
Avoid reading/hashing the inner stream(s) if the leader stream is empty Avoid reading/hashing the inner stream(s) if the leader stream is empty
[18.01.2025] pzotov
Resultset of cursor that executes using instance of selectable PreparedStatement must be stored
in some variable in order to have ability close it EXPLICITLY (before PS will be freed).
Otherwise access violation raises during Python GC and pytest hangs at final point (does not return control to OS).
This occurs at least for: Python 3.11.2 / pytest: 7.4.4 / firebird.driver: 1.10.6 / Firebird.Qa: 0.19.3
The reason of that was explained by Vlad, 26.10.24 17:42 ("oddities when use instances of selective statements").
Checked on 6.0.0.457, 5.0.2.1499 Checked on 6.0.0.457, 5.0.2.1499
""" """
import zipfile import zipfile
@ -57,17 +64,29 @@ def test_1(act: Action, tmp_fbk: Path, capsys):
with act.db.connect() as con: with act.db.connect() as con:
cur = con.cursor() cur = con.cursor()
ps, rs = None, None
try:
ps = cur.prepare(test_sql) ps = cur.prepare(test_sql)
print( '\n'.join([replace_leading(s) for s in ps.detailed_plan.split('\n')]) ) print( '\n'.join([replace_leading(s) for s in ps.detailed_plan.split('\n')]) )
try: # ::: NB ::: 'ps' returns data, i.e. this is SELECTABLE expression.
cur.execute(ps) # We have to store result of cur.execute(<psInstance>) in order to
for r in cur: # close it explicitly.
# Otherwise AV can occur during Python garbage collection and this
# causes pytest to hang on its final point.
# Explained by hvlad, email 26.10.24 17:42
rs = cur.execute(ps)
for r in rs:
for p in r: for p in r:
print(p) print(p)
except DatabaseError as e: except DatabaseError as e:
print(e.__str__()) print(e.__str__())
print(e.gds_codes) print(e.gds_codes)
finally:
if rs:
rs.close() # <<< EXPLICITLY CLOSING CURSOR RESULTS
if ps:
ps.free()
expected_stdout_5x = """ expected_stdout_5x = """
Select Expression Select Expression