Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ async def send_request(
body_str = json.dumps(body)
headers = {'Content-Length': str(len(body_str)),
'Content-Type': "application/vnd.schemaregistry.v1+json",
'Accept-Version': "8.0"}
'Confluent-Accept-Unknown-Properties': "true"}

if self.bearer_auth_credentials_source:
await self.handle_bearer_auth(headers)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ def send_request(
body_str = json.dumps(body)
headers = {'Content-Length': str(len(body_str)),
'Content-Type': "application/vnd.schemaregistry.v1+json",
'Accept-Version': "8.0"}
'Confluent-Accept-Unknown-Properties': "true"}

if self.bearer_auth_credentials_source:
self.handle_bearer_auth(headers)
Expand Down
2 changes: 2 additions & 0 deletions src/confluent_kafka/schema_registry/common/avro.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ def transform(
return message
fields = schema["fields"]
for field in fields:
if field["name"] not in message:
continue
_transform_field(ctx, schema, field, message, field_transform)
return message

Expand Down
62 changes: 62 additions & 0 deletions tests/schema_registry/_async/test_avro_serdes.py
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,68 @@ async def test_avro_cel_field_transform():
assert obj2 == newobj


async def test_avro_cel_field_transform_missing_prop():
conf = {'url': _BASE_URL}
client = AsyncSchemaRegistryClient.new_client(conf)
ser_conf = {'auto.register.schemas': False, 'use.latest.version': True}
schema = {
'type': 'record',
'name': 'test',
'fields': [
{'name': 'intField', 'type': 'int'},
{'name': 'doubleField', 'type': 'double'},
{'name': 'stringField', 'type': 'string'},
{'name': 'booleanField', 'type': 'boolean'},
{'name': 'bytesField', 'type': 'bytes'},
{'name': 'missing', 'type': ['null', 'string'], 'default': None},
]
}

rule = Rule(
"test-cel",
"",
RuleKind.TRANSFORM,
RuleMode.WRITEREAD,
"CEL_FIELD",
None,
None,
"name == 'stringField' ; value + '-suffix'",
None,
None,
False
)
await client.register_schema(_SUBJECT, Schema(
json.dumps(schema),
"AVRO",
[],
None,
RuleSet(None, [rule])
))

obj = {
'intField': 123,
'doubleField': 45.67,
'stringField': 'hi',
'booleanField': True,
'bytesField': b'foobar',
}
ser = await AsyncAvroSerializer(client, schema_str=None, conf=ser_conf)
ser_ctx = SerializationContext(_TOPIC, MessageField.VALUE)
obj_bytes = await ser(obj, ser_ctx)

obj2 = {
'intField': 123,
'doubleField': 45.67,
'stringField': 'hi-suffix-suffix',
'booleanField': True,
'bytesField': b'foobar',
'missing': None,
}
deser = await AsyncAvroDeserializer(client)
newobj = await deser(obj_bytes, ser_ctx)
assert obj2 == newobj


async def test_avro_cel_field_transform_disable():
conf = {'url': _BASE_URL}
client = AsyncSchemaRegistryClient.new_client(conf)
Expand Down
62 changes: 62 additions & 0 deletions tests/schema_registry/_sync/test_avro_serdes.py
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,68 @@ def test_avro_cel_field_transform():
assert obj2 == newobj


def test_avro_cel_field_transform_missing_prop():
conf = {'url': _BASE_URL}
client = SchemaRegistryClient.new_client(conf)
ser_conf = {'auto.register.schemas': False, 'use.latest.version': True}
schema = {
'type': 'record',
'name': 'test',
'fields': [
{'name': 'intField', 'type': 'int'},
{'name': 'doubleField', 'type': 'double'},
{'name': 'stringField', 'type': 'string'},
{'name': 'booleanField', 'type': 'boolean'},
{'name': 'bytesField', 'type': 'bytes'},
{'name': 'missing', 'type': ['null', 'string'], 'default': None},
]
}

rule = Rule(
"test-cel",
"",
RuleKind.TRANSFORM,
RuleMode.WRITEREAD,
"CEL_FIELD",
None,
None,
"name == 'stringField' ; value + '-suffix'",
None,
None,
False
)
client.register_schema(_SUBJECT, Schema(
json.dumps(schema),
"AVRO",
[],
None,
RuleSet(None, [rule])
))

obj = {
'intField': 123,
'doubleField': 45.67,
'stringField': 'hi',
'booleanField': True,
'bytesField': b'foobar',
}
ser = AvroSerializer(client, schema_str=None, conf=ser_conf)
ser_ctx = SerializationContext(_TOPIC, MessageField.VALUE)
obj_bytes = ser(obj, ser_ctx)

obj2 = {
'intField': 123,
'doubleField': 45.67,
'stringField': 'hi-suffix-suffix',
'booleanField': True,
'bytesField': b'foobar',
'missing': None,
}
deser = AvroDeserializer(client)
newobj = deser(obj_bytes, ser_ctx)
assert obj2 == newobj


def test_avro_cel_field_transform_disable():
conf = {'url': _BASE_URL}
client = SchemaRegistryClient.new_client(conf)
Expand Down