Skip to content

Python Kafka structured JSON regresses from data object to data_base64 #701

Done
clemensv/real-time-sources
#1747

Description

@clemensv

Regenerating an unchanged JsonStructure-backed Python Kafka producer with xrcg 0.11.1 changes structured JSON CloudEvents from a JSON data object to data_base64. Existing consumers reading data break. Reproducer: generate kafkaproducer/py for a record schema, instantiate the generated EventProducer with content_mode="structured", send the record through a recording Producer, and json.loads the produced value. Expected: data is the record object; actual: data_base64 contains its JSON bytes. Root cause in xrcg/templates/py/kafkaproducer/src/{mainprojectdir!dotunderscore!lower}producer.py.jinja: CloudEvent.create receives pre-serialized bytes before to_structured runs. Preserve JSON-compatible structured data while retaining bytes/base64 for non-JSON content and retaining binary-mode bytes. Observed during Pegelonline regeneration; contracts and key/subject templates are unchanged. A source-template fix and focused regression test are being prepared locally.

Activity

  1. clemensv commented on Nov 16, 2026

    @clemensv
    CollaboratorAuthor

    A local source-template fix now preserves JSON data objects for application/json (including parameters) and +json structured CloudEvents; binary Kafka and structured XML/base64 remain unchanged. The existing test_generated_dataschema_overrides now checks payload shape as well as URI replacement, copied maps, and non-recursive lookup. All 10 targeted upstream cases and all 75 Pegelonline source/authoring tests pass after regeneration. Fix is currently uncommitted in the local codegen checkout; no generated source files were hand-edited.

  2. clemensv commented on Nov 16, 2026

    @clemensv
    CollaboratorAuthor

    Final local validation: all 3 Pegelonline Docker E2E flows passed against real upstream reference and telemetry events (Kafka, MQTT, AMQP), in addition to the 10 generator regressions and 75 source/authoring tests. Corrected Kafka JSON wire shape re-reviewed by JSON Structure and Avro reviewers: GO. Container validation used the machine package mirror after public package downloads failed TLS negotiation; no TLS verification was disabled. The fix remains local/uncommitted.

  3. clemensv commented on Nov 24, 2026

    @clemensv
    CollaboratorAuthor

    The correction is now included in #712. Generated-runtime regressions verify object-valued JSON data and unchanged raw Avro data_base64. Four source-level structured JSON regressions exposed the unchanged upstream template during regeneration; the corrected combined source/generated suite passes 307 tests.

  4. clemensv commented on Nov 29, 2026

    @clemensv
    CollaboratorAuthor

    Reproduced again with the actual published xrcg 0.11.3 wheel, accepted commit c48d405. The first fresh NDW Kafka runtime test fails its unchanged object-data assertion after regeneration.

    The current Python Kafka template always passes pre-serialized bytes to CloudEvent.create and a bytes-returning marshaller to to_structured. The previous generated producer passed a JSON object to the structured formatter. This changes application/json events from data: { ... } to data_base64.

    The SDK is behaving as CloudEvents JSON Format 3.1.1 requires for Binary runtime data; this is a producer compatibility regression, not an invalid base64 envelope. Existing receivers expect the prior object-data shape. Contracts, generated output and receiver assertions will not be patched to conceal it.

    The current test_python_producer_inherited_avro_content_type also unconditionally requires data_base64, even for its application/json cases. I am correcting that expectation and verifying default/explicit structured JSON, JSON media-type parameters and +json, alongside unchanged non-JSON Avro base64 and binary-mode bytes.

    The user approved an upstream template repair and fresh immutable 0.11.4 through normal CLI release gates. 0.11.3 will not be retagged or overwritten. No downstream workaround has been applied.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions