neo4rs icon indicating copy to clipboard operation
neo4rs copied to clipboard

CREATE statement does nothing if the result isn't iterated

Open rick-carpool opened this issue 1 year ago • 1 comments

version: 0.6.2

client.execute(query("create (n:MyNode {p: 'prop})")).await.unwrap();

returns with no error but also does nothing.

let mut result = client.execute(query("create (n:MyNode {p: 'prop})")).await.unwrap();
while let Ok(Some(row)) = result.next().await {}

writes to the db as expected.

rick-carpool avatar Sep 12 '23 20:09 rick-carpool

That behavior is by design, basically. Bolt is a stateful protocol and calling execute will return a RowStream that is in the READY state.

At this point, the server has parsed and validated the query, produced a plan and returned the result schema to the client. It is ready to produce results, but it's waiting for the client to be told to do so, which will happen on the first call to next. This streaming happens in chunks (config.fetch_size) and looping through all the calls to next ensures that all of those chunks are requested and executed on the server.

If you want to run a query for its side effects, you should use run instead of execute. I am also adding must_use to RowStream, which would at least give you a warning:

warning: unused `RowStream` that must be used
  --> lib/tests/result_stream.rs:27:5
   |
27 | /     graph
28 | |         .execute(query("CREATE (n:MyNode {p: 'prop'})"))
29 | |         .await
30 | |         .unwrap();
   | |_________________^
   |
   = note: Results must be streamed through with `next` in order to execute the query
   = note: `#[warn(unused_must_use)]` on by default

knutwalker avatar Sep 29 '23 15:09 knutwalker