Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Driver does not appear to properly destroy resources #605

Open
james-whiteside opened this issue Feb 29, 2024 · 0 comments
Open

Driver does not appear to properly destroy resources #605

james-whiteside opened this issue Feb 29, 2024 · 0 comments

Comments

@james-whiteside
Copy link
Contributor

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:

  • 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:

with TypeDB.core_driver(ADDRESS) as driver:
    with driver.session(DATABASE, SessionType.DATA) as session:
        with session.transaction(TransactionType.READ) as transaction:
            results = transaction.query.fetch("""
                match
                $book isa book;
                fetch
                $book: title, page-count;
            """)

            # Note indentation of this block in each example
            for result in results:
                print(result)

Session scope:

with TypeDB.core_driver(ADDRESS) as driver:
    with driver.session(DATABASE, SessionType.DATA) as session:
        with session.transaction(TransactionType.READ) as transaction:
            results = transaction.query.fetch("""
                match
                $book isa book;
                fetch
                $book: title, page-count;
            """)

        for result in results:
            print(result)

Driver scope:

with TypeDB.core_driver(ADDRESS) as driver:
    with driver.session(DATABASE, SessionType.DATA) as session:
        with session.transaction(TransactionType.READ) as transaction:
            results = transaction.query.fetch("""
                match
                $book isa book;
                fetch
                $book: title, page-count;
            """)

    for result in results:
        print(result)

Out of scope:

with TypeDB.core_driver(ADDRESS) as driver:
    with driver.session(DATABASE, SessionType.DATA) as session:
        with session.transaction(TransactionType.READ) as transaction:
            results = transaction.query.fetch("""
                match
                $book isa book;
                fetch
                $book: title, page-count;
            """)

for result in results:
    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

  1. TypeDB distribution: Core
  2. TypeDB version: 2.25.7
  3. Environment: MacOS
  4. Driver language: Python
  5. Driver version: 2.26.6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants