[ https://issues.apache.org/jira/browse/TINKERPOP-1506?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15622906#comment-15622906 ]
ASF GitHub Bot commented on TINKERPOP-1506: ------------------------------------------- GitHub user okram opened a pull request: https://github.com/apache/tinkerpop/pull/471 TINKERPOP-1506: Optional/Coalesce should not allow sideEffect traversals. https://issues.apache.org/jira/browse/TINKERPOP-1506 `g.V(1).optional(addV())` created 2 vertices, not one. This is because `optional()` was implemented with the branch-step `ChooseStep`. This has been fixed with a custom `OptionalStep`. Test cases added to verify correct behavior. Added to `master/` as this is a breaking change. Though, the previous behavior can easily be deemed a bug. VOTE +1. You can merge this pull request into a Git repository by running: $ git pull https://github.com/apache/tinkerpop TINKERPOP-1506 Alternatively you can review and apply these changes as the patch at: https://github.com/apache/tinkerpop/pull/471.patch To close this pull request, make a commit to your master/trunk branch with (at least) the following in the commit message: This closes #471 ---- commit 40971c95903077d38cb754843eb914b5548f5c1f Author: Marko A. Rodriguez <okramma...@gmail.com> Date: 2016-10-31T18:03:33Z added OptionalStep to be used instead of optional() being backed by ChooseStep. This fixes a side-effect issue. ---- > Optional/Coalesce should not allow sideEffect traversals. > --------------------------------------------------------- > > Key: TINKERPOP-1506 > URL: https://issues.apache.org/jira/browse/TINKERPOP-1506 > Project: TinkerPop > Issue Type: Improvement > Components: process > Affects Versions: 3.1.4, 3.2.2 > Reporter: Marko A. Rodriguez > > It took me a long time to realize what was wrong with a traversal I wrote > that used {{optional(blah.sideEffect.blah)}}. {{optional()}} maps to > {{ChooseStep}} under the hood and the provide traversal is first tested for a > {{hasNext()}}. If so, the it plays itself out. The problem is that if there > is a side-effect in the traversal child, then it gets executed twice. > {code} > gremlin> g = TinkerGraph.open().traversal() > ==>graphtraversalsource[tinkergraph[vertices:0 edges:0], standard] > gremlin> g.inject(1).optional(addV('twin')) > ==>v[1] > gremlin> g.V().valueMap(true) > ==>[id:0,label:twin] > ==>[id:1,label:twin] > {code} > We should NOT allow {{optional()}} to have {{SideEffectStep}} steps in it so > as not to cause unexpected behavior. {{StandardVerificationStrategy}} can > analyze and throw an exception if necessary. > Also, {{coalesce()}} has a similar problem, though perhaps it can be a useful > 'technique.' > {code} > gremlin> g = TinkerGraph.open().traversal() > ==>graphtraversalsource[tinkergraph[vertices:0 edges:0], standard] > gremlin> g.inject(1).coalesce(addV('twin1').limit(0), addV('twin2')) > ==>v[1] > gremlin> g.V().valueMap(true) > ==>[id:0,label:twin1] > ==>[id:1,label:twin2] > gremlin> > {code} -- This message was sent by Atlassian JIRA (v6.3.4#6332)