Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ image::https://raw.githubusercontent.com/apache/tinkerpop/master/docs/static/ima

This release also includes changes from prior 3.7.x releases.

* Fixed `AddPropertyStep` not passing the old property to `EventStrategy` listeners when the cardinality was not specified in `property()`.

[[release-3-8-2]]
=== TinkerPop 3.8.2 (Release Date: September 1, 2026)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,24 +104,24 @@ protected void sideEffect(final Traverser.Admin<S> traverser) {
"Property cardinality can only be set for a Vertex but the traversal encountered %s for key: %s",
element.getClass().getSimpleName(), key));

final VertexProperty.Cardinality effectiveCardinality = this.cardinality != null
? this.cardinality
: element.graph().features().vertex().getCardinality(key);

final Optional<EventStrategy> optEventStrategy = getTraversal().getStrategies().getStrategy(EventStrategy.class);
final boolean eventingIsConfigured = EventUtil.hasAnyCallbacks(callbackRegistry)
&& optEventStrategy.isPresent();
final EventStrategy es = optEventStrategy.orElse(null);

// find property to remove. only need to capture the removedProperty if eventing is configured
final Property removedProperty = eventingIsConfigured ?
captureRemovedProperty(element, key, value, es) :
captureRemovedProperty(element, key, value, effectiveCardinality, es) :

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On 3.7, this cardinality is used only for event capture. The actual write below still calls vertex.property(key, value) when cardinality is omitted, and providers may implement that differently from getCardinality(key), which is documented as potentially only a hint. This could cause the event to report a replacement when the provider actually appended, or miss a replacement when it wrote as single. I fully agree with your fix on 3.8-dev though.

Do you need this fix on 3.7.x or can we just apply it to 3.8.x?

@paul-lartigau paul-lartigau Oct 14, 2026 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, I missed that. I've patched it on my side in a fork for now, so applying it to 3.8.x only is fine, and I'll pick it up there later. I've retargeted this PR to 3.8-dev.

VertexProperty.empty();

final VertexProperty.Cardinality card = this.cardinality != null
? this.cardinality
: element.graph().features().vertex().getCardinality(key);

// update property
if (element instanceof Vertex) {
if (null != card) {
((Vertex) element).property(card, key, value, vertexPropertyKeyValues);
if (null != effectiveCardinality) {
((Vertex) element).property(effectiveCardinality, key, value, vertexPropertyKeyValues);
} else if (vertexPropertyKeyValues.length > 0) {
((Vertex) element).property(key, value, vertexPropertyKeyValues);
} else {
Expand All @@ -140,11 +140,12 @@ protected void sideEffect(final Traverser.Admin<S> traverser) {
}

private Property captureRemovedProperty(final Element element, final String key, final Object value,
final VertexProperty.Cardinality effectiveCardinality,
final EventStrategy es){
Property removedProperty = VertexProperty.empty();

if (element instanceof Vertex) {
if (cardinality == VertexProperty.Cardinality.set) {
if (effectiveCardinality == VertexProperty.Cardinality.set) {
final Iterator<? extends Property> properties = element.properties(key);
while (properties.hasNext()) {
final Property property = properties.next();
Expand All @@ -153,7 +154,7 @@ private Property captureRemovedProperty(final Element element, final String key,
break;
}
}
} else if (cardinality == VertexProperty.Cardinality.single) {
} else if (effectiveCardinality == VertexProperty.Cardinality.single) {
removedProperty = element.property(key);
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.IsInstanceOf.instanceOf;
import static org.junit.Assert.assertEquals;
import static org.junit.Assume.assumeTrue;

/**
* @author Stephen Mallette (http://stephen.genoprime.com)
Expand Down Expand Up @@ -1051,6 +1052,39 @@ public void vertexPropertyChanged(final Vertex element, final VertexProperty old
assertThat(triggered.get(), is(true));
}

@Test
@FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY)
public void shouldCaptureOldVertexPropertyWhenChangedWithDefaultCardinality() {
assumeTrue(graph.features().vertex().getCardinality("to-change") == VertexProperty.Cardinality.single);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fix also changes behavior when the graph’s default cardinality is set, but this test only runs for default single cardinality. Please add a second test for default set and ensure it executes with TinkerGraph by configuring TinkerGraphProvider#getBaseConfiguration() for that test method, following the existing pattern.


final AtomicBoolean triggered = new AtomicBoolean(false);
final Vertex v = graph.addVertex();
v.property("to-change", "blah");

final MutationListener listener = new AbstractMutationListener() {
@Override
public void vertexPropertyChanged(final Vertex element, final VertexProperty oldValue, final Object setValue, final Object... vertexPropertyKeyValues) {
assertEquals("to-change", oldValue.key());
assertEquals("blah", oldValue.value());
assertEquals("dah", setValue);
triggered.set(true);
}
};
final EventStrategy.Builder builder = EventStrategy.build().addListener(listener);

if (graph.features().graph().supportsTransactions())
builder.eventQueue(new EventStrategy.TransactionalEventQueue(graph));

final EventStrategy eventStrategy = builder.create();
final GraphTraversalSource gts = create(eventStrategy);

gts.V(v).property("to-change", "dah").iterate();
tryCommit(graph);

assertEquals(1, IteratorUtils.count(g.V(v).properties()));
assertThat(triggered.get(), is(true));
}

@Test
@FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY)
public void shouldDetachVertexPropertyWhenNew() {
Expand Down
Loading