Skip to content

MERGE's ON CREATE/ON MATCH SET re-implements SET and silently drops dynamic-key and expression-target items #6831

Closed

Description

@ruispereira

Summary

MergeStep.applySetClause is a private second implementation of the SET clause, used for ON CREATE SET / ON MATCH SET. It handles only the variable.property shape, so the dynamic-key form and the expression-target forms - both of which the shared parser happily produces for a MERGE action - are silently dropped with no error.

Where (HEAD 9c9d024db)

engine/src/main/java/com/arcadedb/query/opencypher/executor/steps/MergeStep.java:1351-1360, the case PROPERTY: branch reads only two fields:

final Object obj = result.getProperty(variable);   // :1352
...
final String property = item.getProperty();        // :1360

It never looks at SetItem.getKeyExpression() or SetItem.getTargetExpression(), which SetStep does handle (SetStep.java:174 for the dynamic key, :227 for the expression target).

visitMergeClause builds the merge actions with the shared visitSetClause (CypherASTBuilder.java:812), so both shapes reach applySetClause:

  • the dynamic-key form (CypherASTBuilder.java:712) arrives with property == null and the key in keyExpression
  • the expression-target forms (:696, :701, :715) arrive with variable == null

Consequences:

  1. variable == null makes result.getProperty(null) return null (ResultInternal.java:149 has no null-name case), so the switch hits continue at :1355 and the SET item vanishes.
  2. For the dynamic-key form property is null, so the code calls doc.has(null) / mutableDoc.set(null, coerced); MutableDocument.set does map.put(name, ...) into a LinkedHashMap (MutableDocument.java:195), so the computed key is never used.
  3. The branch also skips the validatePropertyValue() guard SetStep applies (SetStep.java:265), so ON CREATE SET n.p = {a:1} stores a map as a property value where the identical plain SET raises TypeError: InvalidPropertyType.

Repro

CREATE (:P {id:1});
MERGE (n:P {id:1}) ON MATCH SET n[$k] = 5       -- with $k = 'score'

No score property is written and no error is raised. Likewise:

MERGE (n:P {id:1}) ON MATCH SET (CASE WHEN true THEN n END).x = 1

is a silent no-op.

OpenCypherDynamicPropertyMutationIssue5141Test covers exactly these two forms for plain SET/REMOVE - that is what #5141 fixed - but contains no MERGE case, so the regression suite never reaches this copy of the logic.

Suggested fix

Make MergeStep.applySetClause delegate to the same code path as SetStep: extract SetStep's applyPropertySet/applyReplaceMap/applyMergeMap/applyLabels into a shared helper and call it from both, instead of maintaining a second switch that has to be kept in sync by hand. (See also the companion issue about SET n = <node>, which is the mirror-image divergence: there the MergeStep copy is the one that is right.)

Scope / confidence

High. Verified that the merge actions are not parsed by a restricted builder, that CypherSemanticValidator.validateSetClauseScope (:1099) only checks variable scope, and that ResultInternal.getProperty does not throw on a null name.

Activity

  1. added this to the 26.9.1 milestone on Aug 27, 2026
  2. added
    in progress
    on Aug 28, 2026
  3. self-assigned this
    on Aug 28, 2026
  4. added a commit that references this issue on Aug 28, 2026
  5. added a commit that references this issue on Aug 28, 2026
  6. removed
    in progress
    on Sep 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions