# Driver.execute\_query for queries calling APOC stored procedures

**URL:** <https://community.neo4j.com/t/driver-execute-query-for-queries-calling-apoc-stored-procedures/62995>\
**Category:** Python\
**Created:** [June 20, 2023, 11:34pm UTC](https://community.neo4j.com/t/driver-execute-query-for-queries-calling-apoc-stored-procedures/62995 "2023-06-20T23:34:41Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![shsamardar](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/shsamardar/32/33508_2.png) [@shsamardar](https://community.neo4j.com/u/shsamardar)\
**Post date:** [June 20, 2023, 11:34pm UTC](https://community.neo4j.com/t/driver-execute-query-for-queries-calling-apoc-stored-procedures/62995/1 "2023-06-20T23:34:41Z")

</div>

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

```auto
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:

```auto
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

```auto
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 ?

---

<div class="post-metadata">

**Author:** ![florent\_biville](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/florent_biville/32/14205_2.png) [@florent\_biville](https://community.neo4j.com/u/florent_biville)\
**Post date:** [June 21, 2023, 1:43pm UTC](https://community.neo4j.com/t/driver-execute-query-for-queries-calling-apoc-stored-procedures/62995/2 "2023-06-21T13:43:31Z")

</div>

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`.

---

<div class="post-metadata">

**Author:** ![shsamardar](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/shsamardar/32/33508_2.png) [@shsamardar](https://community.neo4j.com/u/shsamardar)\
**Post date:** [June 21, 2023, 2:38pm UTC](https://community.neo4j.com/t/driver-execute-query-for-queries-calling-apoc-stored-procedures/62995/3 "2023-06-21T14:38:58Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![florent\_biville](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/florent_biville/32/14205_2.png) [@florent\_biville](https://community.neo4j.com/u/florent_biville)\
**Post date:** [June 22, 2023, 8:42am UTC](https://community.neo4j.com/t/driver-execute-query-for-queries-calling-apoc-stored-procedures/62995/4 "2023-06-22T08:42:51Z")

</div>

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 ^^

---

<div class="post-metadata">

**Author:** ![rouven\_bauer](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/rouven_bauer/32/16547_2.png) [@rouven\_bauer](https://community.neo4j.com/u/rouven_bauer)\
**Post date:** [June 27, 2023, 11:19am UTC](https://community.neo4j.com/t/driver-execute-query-for-queries-calling-apoc-stored-procedures/62995/5 "2023-06-27T11:19:54Z")

</div>

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

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

```

is the same as

```python
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).
