gremlin-scala icon indicating copy to clipboard operation
gremlin-scala copied to clipboard

updateWith not handling Option correctly

Open SmedbergM opened this issue 7 years ago • 2 comments

It looks like ScalaVertex.updateWith is not correctly handling updates where the updating case class has members of type Option[T] and value None.

Here's a minimal working example:

object UpdateWithMWE extends App {
  case class XYZ(x: Int, y: String, z: Option[String])

  val xyz0 = XYZ(17,"foo", Some("bar"))
  val xyz1 = XYZ(21,"baz", None)

  val g = Neo4jGraph.open("/tmp/testdb")

  val v0 = g + xyz0
  println(v0.valueMap)
  // prints Map(x -> 17, y -> foo, z -> bar)

  v0.updateWith(xyz1)
  println(v0.valueMap)
  // prints Map(x -> 21, y -> baz, z -> bar, __gs -> )
}

I would expect the result of calling v0.updateWith(xyz1) to be to remove the vertex's z property, since the property can't be None or null.

This behavior is caused by the implementation of updateWith, which uses fromCC(xyz1)'s valueMap, which omits all the None members.

SmedbergM avatar Aug 19 '16 21:08 SmedbergM

Agreed. Thanks for the PR, just merged.

mpollmeier avatar Aug 20 '16 19:08 mpollmeier

IIRC the implementation was done this way to preserve functional symmetry with toCC. Since toCC allows to map a graph element to different case classes, one might argue that updateWith should allow to map from different case classes. Of course, the behavior @SmedbergM described is clearly a bug.

mikolak-net avatar Jan 15 '17 12:01 mikolak-net