Aiven-Open/karapace

Schema not getting register if the order of types are changed.

sp1rs opened this issue · 0 comments

sp1rs commented

What happened?

With compatibility set to full transitive, If I try to update the proto and just change the order of message and enum type in the file, the schema registry fails to registry the schema.

For example, I have the following proto, and I registry it in the schema registry.

FUGA_PROTO = """
syntax = "proto3";
package tc4;

message Fred {
  HodoCode hodecode = 1;
}

enum HodoCode {
  HODO_CODE_UNSPECIFIED = 0;
}
"""

Now If I update the proto (adding 1 field in message Fred) and change the order of message and enum shown below (Note I have written enum first and message type later).

FUGA_UPDATED_PROTO = """
syntax = "proto3";
package tc4;

enum HodoCode {
  HODO_CODE_UNSPECIFIED = 0;
}

message Fred {
  HodoCode hodecode = 1;
  string id = 2;
}
"""

The registry fails to registry(or update) the schema with the following error.

Traceback (most recent call last):
  File "/venv/lib/python3.10/site-packages/karapace/rapu.py", line 329, in _handle_request
    data = await callback(**callback_kwargs)
  File "/venv/lib/python3.10/site-packages/karapace/schema_registry_apis.py", line 1240, in subject_post
    raise xx
  File "/venv/lib/python3.10/site-packages/karapace/schema_registry_apis.py", line 1207, in subject_post
    schema_id = await self.schema_registry.write_new_schema_local(subject, new_schema, references)
  File "/venv/lib/python3.10/site-packages/karapace/schema_registry.py", line 393, in write_new_schema_local
    result = check_compatibility(
  File "/venv/lib/python3.10/site-packages/karapace/compatibility/__init__.py", line 175, in check_compatibility
    result = check_protobuf_compatibility(
  File "/venv/lib/python3.10/site-packages/karapace/compatibility/__init__.py", line 68, in check_protobuf_compatibility
    return check_protobuf_schema_compatibility(reader, writer)
  File "/venv/lib/python3.10/site-packages/karapace/compatibility/protobuf/checks.py", line 12, in check_protobuf_schema_compatibility
    writer.compare(reader, result)
  File "/venv/lib/python3.10/site-packages/karapace/protobuf/schema.py", line 585, in compare
    return self.proto_file_element.compare(
  File "/venv/lib/python3.10/site-packages/karapace/protobuf/proto_file_element.py", line 147, in compare
    return compare_type_lists(self.types, other.types, result, compare_types)
  File "/venv/lib/python3.10/site-packages/karapace/protobuf/compare_type_lists.py", line 72, in compare_type_lists
    raise IllegalStateException("Instance of element is not applicable")
karapace.protobuf.exception.IllegalStateException: Instance of element is not applicable

Note: If I do not change the order of enum and message type, the code work as expected.

What did you expect to happen?

The expected behavior should be that the registry should not fail and it should register the schema.

What else do we need to know?

I tested the same scenario in the confluent registry and it is working fine.