Skip to content

Plain ["null","int"] union field cannot be serialized — bare value and wrapped {"int": N} both fail (v2.1.0, also v1.3.0) #408

Description

@sagarkancharla19

Environment

  • k6 v1.7.1 (go1.26.4, windows/amd64) — prebuilt binary from the releases page
  • Extensions:
    • github.com/mostafa/xk6-kafka/v2 v2.1.0, k6/x/kafka [js]
    • github.com/oleiade/xk6-kv v1.3.0 (unrelated)
  • Confluent Schema Registry with basic auth; schema fetched via schemaRegistry.getSchema() and serialized with SCHEMA_TYPE_AVRO

Schema fragment

The failing field sits inside an array of records (billOfMaterial.lines[]):

{"name": "lineNumber", "type": ["null", "int"], "default": null}

Reproduction

Case 1 — bare value (as documented in the README: "you can usually provide union values directly without wrapping them"):

"lineNumber": 1

fails with:

ERRO[0002] GoError: Failed to encode data into binary, OriginalError: billOfMaterial: lines: []interface {}: []interface {}: lineNumber: avro: unknown union type double
  at github.com/mostafa/xk6-kafka/v2/pkg/kafka.(*Kafka).schemaRegistryClientClass.func4 (native)

Case 2 — wrapped primitive (per the v1.3.0 release notes / schema-registry docs):

"lineNumber": {"int": 1}

fails with:

ERRO[0002] GoError: Failed to encode data into binary, OriginalError: billOfMaterial: lines: []interface {}: []interface {}: lineNumber: avro: float64 is unsupported for Avro int
  at github.com/mostafa/xk6-kafka/v2/pkg/kafka.(*Kafka).schemaRegistryClientClass.func4 (native)

Expected behavior

Either representation should serialize, given the documented "automatic conversion of JavaScript float64 to Avro int32/int64" and the wrapped-primitive union support added in v1.3.0.

Actual behavior

Both representations fail, so there is currently no working input representation for a plain ["null","int"] union field. It looks like the float64 normalization applied to logical-type unions (e.g. int.date) does not run for plain int/long union branches — JS numbers arrive as float64 and are never converted before hamba/avro resolves or encodes the branch.

Additional observations

  • Reproduces identically on the v1.3.0 prebuilt binary (same two errors, github.com/mostafa/xk6-kafka.(*Kafka).schemaRegistryClientClass.func4), so it affects the hamba-based serde in both the v1 and v2 lines.
  • Works on v1.1.0 (last goavro-based release) using the wrapped form {"int": 1} — currently my workaround, but I'd like to move back to v2.x for the confluent-kafka-go performance.

Happy to provide a full minimal script or test against a patch. Thanks for the great extension!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions