Skip to content

Commit

Permalink
sr/sharded_store: verbose messages on post schema
Browse files Browse the repository at this point in the history
When an incompatible schema is posted, include the verbose compatibility
messages in the error message.

This helps users understand the reason for the incompatibility and it
matches the reference implementation.

Includes a minor fix to the way the compatibility level message is
formatted.
  • Loading branch information
pgellert committed Aug 27, 2024
1 parent 4c87c5e commit cda768b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/v/pandaproxy/schema_registry/sharded_store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -201,14 +201,15 @@ sharded_store::get_schema_version(subject_schema schema) {
// Check compatibility of the schema
if (!v_id.has_value() && !versions.empty()) {
auto compat = co_await is_compatible(
versions.back().version, schema.schema.share());
if (!compat) {
versions.back().version, schema.schema.share(), verbose::yes);
if (!compat.is_compat) {
throw exception(
error_code::schema_incompatible,
fmt::format(
"Schema being registered is incompatible with an earlier "
"schema for subject \"{}\"",
sub));
"schema for subject \"{}\", details: [{}]",
sub,
fmt::join(compat.messages, ", ")));
}
}
co_return has_schema_result{s_id, v_id};
Expand Down Expand Up @@ -826,7 +827,7 @@ ss::future<compatibility_result> sharded_store::do_is_compatible(
version_messages.emplace_back(
fmt::format("{{oldSchema: '{}'}}", to_string(old_valid.raw())));
version_messages.emplace_back(
fmt::format("{{compatibility: {}}}", compat));
fmt::format("{{compatibility: '{}'}}", compat));
}

result.messages.reserve(
Expand Down
11 changes: 11 additions & 0 deletions tests/rptest/tests/schema_registry_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1588,6 +1588,17 @@ def test_compatibility_messages(self, schemas):
message in m for m in msgs
), f"Expected to find an instance of '{message}', got {msgs}"

self.logger.debug(
"Check post incompatible schema error message (expect verbose messages)"
)
result_raw = self._post_subjects_subject_versions(
subject=f"{topic}-key", data=incompatible_data)

assert result_raw.status_code == 409
msg = result_raw.json()["message"]
for message in ["oldSchemaVersion", "oldSchema", "compatibility"]:
assert message in msg, f"Expected to find an instance of '{message}', got {msgs}"

@cluster(num_nodes=3)
def test_delete_subject(self):
"""
Expand Down

0 comments on commit cda768b

Please sign in to comment.