Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set avro/json schema on use.latest.version=True #1704

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

ifnesi
Copy link

@ifnesi ifnesi commented Jan 17, 2024

The current AvroSerializer (src/confluent_kafka/schema_registry/avro.py) and JSONSerializer (src/confluent_kafka/schema_registry/json_schema.py) classes do not override the schema when use.latest.schema is set to True, it currently only returns the schema_id. This PR is to address that.

Please notice the same behaviour happens with ProtobufSerializer (src/confluent_kafka/schema_registry/protobuf.py), however not sure how use.latest.schema could work with Protobuf schemas as it needs to be "compiled" and the SR stores the "uncompiled" version of it. Maybe we should drop that configuration parameter out?

@ifnesi ifnesi requested a review from a team as a code owner January 17, 2024 13:33
Copy link

cla-assistant bot commented Jan 17, 2024

CLA assistant check
All committers have signed the CLA.

Copy link
Member

@pranavrth pranavrth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for submitting the PR.

Please update the PR with the following:

  1. Rebase the PR
  2. Test cases for the fix
  3. CHANGELOG entry

Done review of the code part of the PR. I am going to test these changes once you have updated the PR with the requested changes and provide more comments if required.

I am checking the Protobuf part.

raise TypeError('You must pass either schema string or schema object')

self._to_dict = to_dict
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this necessary? The validation of to_dict happens at line 195. This change should be reverted.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will move the two validation IFs to the start of the method. We still need self._to_dict = to_dict because it is an instance variable required on other class methods

Comment on lines +241 to +244
if isinstance(schema_str, str):
self._schema = _schema_loads(schema_str)
else: # type=Schema (asserted on __init__)
self._schema = schema_str
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This block is only applicable for __init__ function. We always get object of Schema type from the __call__ function. I think its better to keep this as it was earlier and assume that only Schema type object is received here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, but to avoid calling that twice I moved that to _set_instance_variables so either be called on either __init__ or __call__

# on __call__ if use.latest.version is set to True
self._set_instance_variables(schema_str)

def _set_instance_variables(self, schema_str, schema_id=None):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. use schema instead of schema_str here.
  2. Name of the function should be more specific. Something like update_schema_info

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment on lines 232 to 233
Function to be called upon __init__ and when serializing a message (__call__)
if use.latest.version is set True
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add explanation of what this function does as well. This can be written after the description.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comments as Avro file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants