memgraph / mage

MAGE - Memgraph Advanced Graph Extensions :crystal_ball:
Apache License 2.0
244 stars 24 forks source link

It++ std::variant is valueless, possible Iterator problem #387

Open mpintaric55334 opened 10 months ago

mpintaric55334 commented 10 months ago

void list_nodes(mgp_list args, mgp_graphmemgraph_graph, mgp_result result, mgp_memorymemory) { mgp::memory = memory;

mgp::Graph g(memgraph_graph);
const auto record_factory = mgp::RecordFactory(result);

auto nodes = g.Nodes();

auto it = nodes.begin();
while (it != nodes.end()) {
    mgp::Node node = *it;
    int64_t id = node.Id().AsInt();
    std::unordered_map<std::string, mgp::Value> props = node.Properties();
    auto pIt = props.begin();
    while(pIt != props.end()) {
        auto record = record_factory.NewRecord();
        record.Insert("id", id);
        record.Insert("property_name", pIt->first);
        record.Insert("type", TypeToString(pIt->second.Type()));
        record.Insert("value", pIt->second.ToString());
        pIt++;
    }
    it++;
}

}

User provided us with this code of their custom QM function. When using it++, a std::variant is valueless exception is thrown. This happens when it++ is called for the second time. When using ++it, everything works good. This could happen because something is missing from Cpp API?

antejavor commented 10 months ago

Same issue: https://github.com/memgraph/mage/issues/380