You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When iterating through the results of a Fetch query using the Python driver, the iterator sometimes returns results outside of the scope of the transaction object, suggesting it is not properly destroyed when it leaves context. In fact, depending on the scope in which the iterator is called, three different outcomes appear to occur:
Results are returned, indicating transaction object is not destroyed.
Exception is thrown, indicating transaction object is destroyed.
Nothing happens, indicating that the iterator has hit StopIteration.
The following code snippets illustrate the iterator being called in different scopes.
Transaction scope:
withTypeDB.core_driver(ADDRESS) asdriver:
withdriver.session(DATABASE, SessionType.DATA) assession:
withsession.transaction(TransactionType.READ) astransaction:
results=transaction.query.fetch(""" match $book isa book; fetch $book: title, page-count; """)
# Note indentation of this block in each exampleforresultinresults:
print(result)
Session scope:
withTypeDB.core_driver(ADDRESS) asdriver:
withdriver.session(DATABASE, SessionType.DATA) assession:
withsession.transaction(TransactionType.READ) astransaction:
results=transaction.query.fetch(""" match $book isa book; fetch $book: title, page-count; """)
forresultinresults:
print(result)
Driver scope:
withTypeDB.core_driver(ADDRESS) asdriver:
withdriver.session(DATABASE, SessionType.DATA) assession:
withsession.transaction(TransactionType.READ) astransaction:
results=transaction.query.fetch(""" match $book isa book; fetch $book: title, page-count; """)
forresultinresults:
print(result)
Out of scope:
withTypeDB.core_driver(ADDRESS) asdriver:
withdriver.session(DATABASE, SessionType.DATA) assession:
withsession.transaction(TransactionType.READ) astransaction:
results=transaction.query.fetch(""" match $book isa book; fetch $book: title, page-count; """)
forresultinresults:
print(result)
Following several test runs of each code snippet, the following results were observed:
Transaction scope: Prints results (transaction active).
Session scope: Prints results (transaction active), or prints nothing (empty iterator).
Driver scope: Prints nothing (empty iterator), or throws exception (transaction destroyed).
Out of scope: Prints nothing (empty iterator), or throws exception (transaction destroyed).
Environment
TypeDB distribution: Core
TypeDB version: 2.25.7
Environment: MacOS
Driver language: Python
Driver version: 2.26.6
The text was updated successfully, but these errors were encountered:
Description
When iterating through the results of a Fetch query using the Python driver, the iterator sometimes returns results outside of the scope of the transaction object, suggesting it is not properly destroyed when it leaves context. In fact, depending on the scope in which the iterator is called, three different outcomes appear to occur:
StopIteration
.The following code snippets illustrate the iterator being called in different scopes.
Transaction scope:
Session scope:
Driver scope:
Out of scope:
Following several test runs of each code snippet, the following results were observed:
Environment
The text was updated successfully, but these errors were encountered: