What to do with DepracationWarning?

Hi,

I am beginner with Python and Neo4j and I am getting a DepracationWarning. Specifically: DeprecationWarning: Using a driver after it has been closed is deprecated. Future versions of the driver will raise an error.

I verify the driver connection using a with on the top of the script and then execute a query throughout the rest of the script.

Here's the code:

with GraphDatabase.driver(URI, auth=AUTH) as driver:
    driver.verify_connectivity()

def retrieve_from_neo4j(query):
    records, summary, keys = driver.execute_query(
        query,
        database_="neo4j",
    )

    result = []
    # Loop through results and do something with them
    for record in records:
        result.append(record)

    return result

The retrieve_from_neo4j is called many times during one run.

Is the rest of the code running within the scope of this with?

Also, you should specify routing read vs write:

records, summary, keys = driver.execute_query(
        query,
        database_=DB_NAME,
        routing_=RoutingControl.WRITE,
        myParam = someValue
    )

Additionally, are there no parameters for your query?

Hi @hakan.lofqvist1

I just call the with then the rest of the code is outside the with.

Additionally, are there no parameters for your query?

The function retrieve_from_neo4j has a parameter query and when the retieve_from_neo4j is called I pass in Cypher query into that query paramete. Unsure if I understood the question, apologies