memgraph / mage

MAGE - Memgraph Advanced Graph Extensions :crystal_ball:
Apache License 2.0
251 stars 25 forks source link

[BUG] Rust QM API reverts the boolean value from false to true and vice-versa #426

Open antejavor opened 10 months ago

antejavor commented 10 months ago

Here is the simple query that is used to replicate the scenario:

use c_str_macro::c_str;
use rsmgp_sys::memgraph::*;
use rsmgp_sys::mgp::*;
use rsmgp_sys::result::*;
use rsmgp_sys::rsmgp::*;
use rsmgp_sys::value::*;
use rsmgp_sys::{close_module, define_procedure, define_type, init_module};
use std::ffi::CString;
use std::os::raw::c_int;
use std::panic;

init_module!(|memgraph: &Memgraph| -> Result<()> {
    memgraph.add_read_procedure(
        test,
        c_str!("test"),
        &[define_type!("passed", Type::Bool)],
        &[],
        &[define_type!("returned", Type::Bool)],
    )?;

    Ok(())
});

define_procedure!(test, |memgraph: &Memgraph| -> Result<()> {
    let args = memgraph.args()?;
    let Value::Bool(weighted) = args.value_at(0)? else {
        panic!("Failed to read weighted")
    };
    let result = memgraph.result_record()?;
    let _ = result.insert_bool(c_str!("returned"), weighted);

    Ok(())
});

close_module!(|| -> Result<()> { Ok(()) });

Run this in Memgraph:

CALL libhello_world.test(false) YIELD * RETURN *;
risufaj commented 10 months ago

thanks for looking into this @antejavor

garrett-mcclay commented 3 months ago

Please disregard that