Driver.execute_query for queries calling APOC stored procedures

I am using the latest Neo4j Python driver 5.9 that supports driver.execute_query

can the query passed to it be APOC strerd procedure like apoc.path.expandConfig?

I have a query using above apoc that in browser returns rows but not using execute_query

I have written a simple function

def RunQuery  ( driver, query_str , db , parameters ):
    try:
        print ( query_str ) 
        records, summary, keys = driver.execute_query ( query_str , parameters_ = parameters, database = db ) 
        return records, summary, keys 
    except  Exception as e:
        print(e)

my query string is this:

str = '''
match ( t:PartRevision) where t.name = 'CROSSKART_DC' 
WITH t
CALL apoc.path.expandConfig(
    t,
    {
         labelFilter:"PartRevision, Base",
         relationshipFilter:"HAS_PARENT<, +`Latest Working`> | -`Engineering Released`>",
        uniqueness: "NODE_GLOBAL",
        minLevel : 1,
        maxLevel : 3,
        bfs : false
            }) YIELD path
RETURN path , length(path ) as hops 
order by hops
'''

and then i am calling this

r,s,k = RunQuery ( driver,  str ,  db= 'crosscart', parameters = {} ) 

print("The query `{query}` returned {records_count} records in {time} ms.".format(
    query=s.query, records_count=len(r),
    time=s.result_available_after
))

The query match ( t:PartRevision) where t.name = 'CROSSKART_DC' WITH t CALL apoc.path.expandConfig( t, { labelFilter:"PartRevision, Base", relationshipFilter:"HAS_PARENT<, +Latest Working> | -Engineering Released>", uniqueness: "NODE_GLOBAL", minLevel : 1, maxLevel : 3, bfs : false }) YIELD path RETURN path , length(path ) as hops order by hops returned 0 records in 1 ms.

this returns zero rows.

i have tested this process with other queries and it works fine.

i am wondering for a limitation caused by apoc stored procedure. can apoc be called from driver.execute_query ?

Have you tried the exact same query in Neo4j Browser with the same Neo4j instance?
Does it return the same result?

There is no limitation wrt APOC and execute_query.

I noticed the problem .

the parameter name was wrong: i was passing database instead of database_

def RunQuery ( driver, query_str , db , parameters ):
try:
print ( query_str )
records, summary, keys = driver.execute_query ( query_str , parameters_ = parameters, database = db )
return records, summary, keys
except Exception as e:
print(e)

Why wrong parameter name didn't trigger the exception ?

I think one reason is that database_ is not a mandatory parameter.
Maybe the driver could be stricter and fail if extra parameters are passed, but I'm out of my depth here as I don't know much about Python ^^

Why wrong parameter name didn't trigger the exception ?

That's because you can pass any query parameter as keyword parameter.

Here's an example:

driver.execute_query("RETURN $something", something=2)

is the same as

driver.execute_query("RETURN $something", parameters_={"something": 2})

Everything that does not end in an _ is considered a query parameter. Everything ending in an _, however, is considered to be a configuration argument (e.g., the database name to run the query against).

1 Like