Files
tasks/common/sdk/converter.go
Carly de FrondevilleandGitHub 26dddfad3b Ignore unknown fields when decoding Worker Deployment memo for backwards compatibility (#8991)
## What changed?
Ignore unknown fields when decoding Worker Deployment memo for backwards
compatibility

## Why?
New field was added to memo. We want to be able to roll back server and
still list deployments, just without that field

## How did you test it?
Tested it with v148. Also cherry-picked onto v147.6 and ran my unit
test. With the new Lenient converter, the unit test passed as expected.
With the old strict converter, the unit test failed as expected.

- [x] built
- [ ] run locally and tested manually
- [x] covered by existing tests
- [x] added new unit test(s)
- [ ] added new functional test(s)

## Potential risks
Changing the data converter is risky, but in this case, we know we are
decoding a proto, and we have tests covering that decoding, so I think
it's ok

---

> [!NOTE]
> Makes JSON/protobuf memo decoding lenient to support backward
compatibility and adds tests to verify decoding behavior.
> 
> - Update `PreferProtoDataConverter` to use
`NewProtoJSONPayloadConverterWithOptions(AllowUnknownFields: true)`,
causing proto JSON decoding to ignore unknown fields
> - Add `TestDecodeWorkerDeploymentMemoTolerateUnknownFields` and
`TestDecodeWorkerDeploymentMemoTolerateMissingFields` with memo JSON
fixtures to validate `DecodeWorkerDeploymentMemo` succeeds and parses
known fields
> 
> <sup>Written by [Cursor
Bugbot]() for commit
a0d1ea46134d13fd21aaf81da7e97400748fd01a. This will update automatically
on new commits. Configure
[here]().</sup>
2026-01-12 23:39:30 +00:00

19 lines
644 B
Go

package sdk
import (
"go.temporal.io/sdk/converter"
)
var (
// PreferProtoDataConverter is like the default data converter defined in the SDK, except
// that it prefers encoding proto messages with the binary encoding instead of json.
// If decoding with json, allows unknown fields.
PreferProtoDataConverter = converter.NewCompositeDataConverter(
converter.NewNilPayloadConverter(),
converter.NewByteSlicePayloadConverter(),
converter.NewProtoPayloadConverter(),
converter.NewProtoJSONPayloadConverterWithOptions(converter.ProtoJSONPayloadConverterOptions{AllowUnknownFields: true}),
converter.NewJSONPayloadConverter(),
)
)