# Does Neomodel use read\_transaction when running db.cypher\_query()?

**URL:** <https://community.neo4j.com/t/does-neomodel-use-read-transaction-when-running-db-cypher-query/65867>\
**Category:** Python\
**Tags:** neomodel, cypher, ogm\
**Created:** [January 19, 2024, 12:55pm UTC](https://community.neo4j.com/t/does-neomodel-use-read-transaction-when-running-db-cypher-query/65867 "2024-01-19T12:55:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tijana37](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/tijana37/32/29602_2.png) [@Tijana37](https://community.neo4j.com/u/Tijana37)\
**Post date:** [January 19, 2024, 12:55pm UTC](https://community.neo4j.com/t/does-neomodel-use-read-transaction-when-running-db-cypher-query/65867/1 "2024-01-19T12:55:47Z")

</div>

I am using Neomodel as OGM to connect my app with the Neo4j database.  
For the more complex queries I'm using the function:  
neomodel.db.cypher\_query(query, params={})

Now, I can see that Neomodel uses session.run to execute this query, but I'm not sure if it's using read\_transaction or write\_transaction? If it's not explicitly set, the default option is write\_transaction, meaning that Neomodel uses write locks whenever calling db.cypher\_query().

And the approach is very important, as most of this queries are READ ONLY, so it's not needed to put WRITE locks on the nodes in order to be executed!

Thank you in advance!

---

<div class="post-metadata">

**Author:** ![marius.conjeaud](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/marius.conjeaud/32/17461_2.png) [@marius.conjeaud](https://community.neo4j.com/u/marius.conjeaud)\
**Post date:** [February 5, 2024, 9:28am UTC](https://community.neo4j.com/t/does-neomodel-use-read-transaction-when-running-db-cypher-query/65867/2 "2024-02-05T09:28:19Z")

</div>

Hello,

So I've done this simple test of calling `db.cypher_query("CREATE (n:Random)"` without any transaction configuration, and it went through successfully =\> that means it's a write transaction or it would have failed.  
So your assumption is right that it's write transaction by default.

I'm not 100% clear on node locks for nodes that are only being MATCHed though, that would need to be checked.

---

<div class="post-metadata">

**Author:** ![Tijana37](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/tijana37/32/29602_2.png) [@Tijana37](https://community.neo4j.com/u/Tijana37)\
**Post date:** [February 19, 2024, 3:24pm UTC](https://community.neo4j.com/t/does-neomodel-use-read-transaction-when-running-db-cypher-query/65867/3 "2024-02-19T15:24:40Z")

</div>

Thank you for your answer.  
I have extended your test to limit db.cypher\_query() on read mode only. Writing the conclusion here, so it can be helpful for others.

When added @db.read\_transaction wrapper on function or calling the method in clause  
`with db.read_transaction:`, the method db.cypher\_query() executes only read operations and throws error when trying to use write operation.  
For example, this code throws error:

```auto
def tst():
    with db.read_transaction:
        query = """CREATE (n:Random) RETURN n"""
        matches, _ = neomodel.db.cypher_query(query)
    return matches

```

neo4j.exceptions.ClientError: {code: Neo.ClientError.Statement.AccessMode} {message: Writing in read access mode not allowed. Attempted write to neo4j}
