Fix API bug on accessing deleted object (#1209)
This commit is contained in:
committed by
GitHub
parent
07dea328d8
commit
b094fdbadc
@@ -94,6 +94,14 @@ class EdgeAccessor final {
|
||||
|
||||
VertexAccessor From() const;
|
||||
|
||||
/// When edge is deleted and you are accessing To vertex
|
||||
/// for_deleted_ flag will in this case be updated properly
|
||||
VertexAccessor DeletedEdgeToVertex() const;
|
||||
|
||||
/// When edge is deleted and you are accessing From vertex
|
||||
/// for_deleted_ flag will in this case be updated properly
|
||||
VertexAccessor DeletedEdgeFromVertex() const;
|
||||
|
||||
bool IsCycle() const;
|
||||
|
||||
int64_t CypherId() const { return impl_.Gid().AsInt(); }
|
||||
@@ -236,6 +244,12 @@ inline VertexAccessor EdgeAccessor::To() const { return VertexAccessor(impl_.ToV
|
||||
|
||||
inline VertexAccessor EdgeAccessor::From() const { return VertexAccessor(impl_.FromVertex()); }
|
||||
|
||||
inline VertexAccessor EdgeAccessor::DeletedEdgeToVertex() const { return VertexAccessor(impl_.DeletedEdgeToVertex()); }
|
||||
|
||||
inline VertexAccessor EdgeAccessor::DeletedEdgeFromVertex() const {
|
||||
return VertexAccessor(impl_.DeletedEdgeFromVertex());
|
||||
}
|
||||
|
||||
inline bool EdgeAccessor::IsCycle() const { return To() == From(); }
|
||||
|
||||
class SubgraphVertexAccessor final {
|
||||
|
||||
@@ -487,12 +487,16 @@ mgp_value::mgp_value(const memgraph::query::TypedValue &tv, mgp_graph *graph, me
|
||||
edge_v = std::visit(
|
||||
memgraph::utils::Overloaded{
|
||||
[&tv, graph, &allocator](memgraph::query::DbAccessor *) {
|
||||
return allocator.new_object<mgp_edge>(tv.ValueEdge(), graph);
|
||||
return allocator.new_object<mgp_edge>(tv.ValueEdge(), tv.ValueEdge().DeletedEdgeFromVertex(),
|
||||
tv.ValueEdge().DeletedEdgeToVertex(), graph);
|
||||
},
|
||||
[&tv, graph, &allocator](memgraph::query::SubgraphDbAccessor *db_impl) {
|
||||
return allocator.new_object<mgp_edge>(
|
||||
tv.ValueEdge(), memgraph::query::SubgraphVertexAccessor(tv.ValueEdge().From(), db_impl->getGraph()),
|
||||
memgraph::query::SubgraphVertexAccessor(tv.ValueEdge().To(), db_impl->getGraph()), graph);
|
||||
tv.ValueEdge(),
|
||||
memgraph::query::SubgraphVertexAccessor(tv.ValueEdge().DeletedEdgeFromVertex(),
|
||||
db_impl->getGraph()),
|
||||
memgraph::query::SubgraphVertexAccessor(tv.ValueEdge().DeletedEdgeToVertex(), db_impl->getGraph()),
|
||||
graph);
|
||||
}},
|
||||
graph->impl);
|
||||
break;
|
||||
@@ -849,11 +853,16 @@ mgp_value::~mgp_value() noexcept { DeleteValueMember(this); }
|
||||
mgp_edge *mgp_edge::Copy(const mgp_edge &edge, mgp_memory &memory) {
|
||||
return std::visit(
|
||||
memgraph::utils::Overloaded{
|
||||
[&](memgraph::query::DbAccessor *) { return NewRawMgpObject<mgp_edge>(&memory, edge.impl, edge.from.graph); },
|
||||
[&](memgraph::query::DbAccessor *) {
|
||||
return NewRawMgpObject<mgp_edge>(&memory, edge.impl, edge.impl.DeletedEdgeFromVertex(),
|
||||
edge.impl.DeletedEdgeToVertex(), edge.from.graph);
|
||||
},
|
||||
[&](memgraph::query::SubgraphDbAccessor *db_impl) {
|
||||
return NewRawMgpObject<mgp_edge>(
|
||||
&memory, edge.impl, memgraph::query::SubgraphVertexAccessor(edge.impl.From(), db_impl->getGraph()),
|
||||
memgraph::query::SubgraphVertexAccessor(edge.impl.To(), db_impl->getGraph()), edge.to.graph);
|
||||
&memory, edge.impl,
|
||||
memgraph::query::SubgraphVertexAccessor(edge.impl.DeletedEdgeFromVertex(), db_impl->getGraph()),
|
||||
memgraph::query::SubgraphVertexAccessor(edge.impl.DeletedEdgeToVertex(), db_impl->getGraph()),
|
||||
edge.to.graph);
|
||||
}},
|
||||
edge.to.graph->impl);
|
||||
}
|
||||
|
||||
@@ -105,6 +105,15 @@ VertexAccessor EdgeAccessor::ToVertex() const {
|
||||
return VertexAccessor{to_vertex_, transaction_, indices_, constraints_, config_};
|
||||
}
|
||||
|
||||
VertexAccessor EdgeAccessor::DeletedEdgeFromVertex() const {
|
||||
return VertexAccessor{from_vertex_, transaction_, indices_,
|
||||
constraints_, config_, for_deleted_ && from_vertex_->deleted};
|
||||
}
|
||||
|
||||
VertexAccessor EdgeAccessor::DeletedEdgeToVertex() const {
|
||||
return VertexAccessor{to_vertex_, transaction_, indices_, constraints_, config_, for_deleted_ && to_vertex_->deleted};
|
||||
}
|
||||
|
||||
Result<storage::PropertyValue> EdgeAccessor::SetProperty(PropertyId property, const PropertyValue &value) {
|
||||
utils::MemoryTracker::OutOfMemoryExceptionEnabler oom_exception;
|
||||
if (!config_.properties_on_edges) return Error::PROPERTIES_DISABLED;
|
||||
|
||||
@@ -52,6 +52,14 @@ class EdgeAccessor final {
|
||||
|
||||
VertexAccessor ToVertex() const;
|
||||
|
||||
/// When edge is deleted and you are accessing To vertex
|
||||
/// for_deleted_ flag will in this case be updated properly
|
||||
VertexAccessor DeletedEdgeFromVertex() const;
|
||||
|
||||
/// When edge is deleted and you are accessing To vertex
|
||||
/// for_deleted_ flag will in this case be updated properly
|
||||
VertexAccessor DeletedEdgeToVertex() const;
|
||||
|
||||
EdgeTypeId EdgeType() const { return edge_type_; }
|
||||
|
||||
/// Set a property value and return the old value.
|
||||
|
||||
Reference in New Issue
Block a user