-
Notifications
You must be signed in to change notification settings - Fork 129
Description
What is the bug?
In ExplainSMPolicy.kt
, the toXContent()
method incorrectly uses .field()
for the nullable creation
field instead of .optionalField()
. This is inconsistent with how the deletion
field is handled on the same line and with the reference implementation in SMMetadata.toXContent()
. Using .field()
with a nullable value can cause incorrect serialization behavior when the creation workflow metadata is null.
How can one reproduce the bug?
Steps to reproduce the behavior:
- Create a snapshot management policy where the creation workflow metadata can be null
- Call the Explain API to retrieve the policy metadata
- Observe the JSON response when
metadata.creation
is null - See incorrect serialization behavior due to
.field()
being used instead of.optionalField()
What is the expected behavior?
The creation
field should use .optionalField()
to properly handle null values, just like the deletion
field does. When creation
is null, it should be omitted from the JSON response or handled gracefully rather than causing potential serialization issues.
Expected code (line 39 in ExplainSMPolicy.kt):
.optionalField(SMMetadata.CREATION_FIELD, it.creation)
Current (incorrect) code:
.field(SMMetadata.CREATION_FIELD, it.creation)
What is your host/environment?
- OS: N/A (Code-level bug in serialization)
- Version: 3.3.0-SNAPSHOT
- Plugins: OpenSearch Index Management Plugin - Snapshot Management component
Do you have any screenshots?
N/A - This is a code-level serialization bug
Do you have any additional context?
- Location:
src/main/kotlin/org/opensearch/indexmanagement/snapshotmanagement/model/ExplainSMPolicy.kt
, line 39 - Inconsistency: The
deletion
field on line 40 correctly uses.optionalField()
- Reference:
SMMetadata.kt
line 55 shows the correct implementation using.optionalField()
for the creation field - Field Type:
creation
is declared as nullableWorkflowMetadata?
inSMMetadata
(line 42 of SMMetadata.kt) - Root Cause: The creation field was recently changed to be optional (nullable) as part of version 3.3.0 changes, but the ExplainSMPolicy serialization was not updated accordingly