Skip to content

Commit

Permalink
Merge pull request #12956 from BenPope/schema_registry_referenced_by_404
Browse files Browse the repository at this point in the history
schema_registry: /referencedby should emit 404 if sub-ver doesn't exist
  • Loading branch information
BenPope authored Aug 24, 2023
2 parents ce141f5 + 68728a2 commit 64f56c5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/v/pandaproxy/schema_registry/sharded_store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -369,10 +369,18 @@ ss::future<bool> sharded_store::is_referenced(subject sub, schema_version ver) {
ss::future<std::vector<schema_id>> sharded_store::referenced_by(
subject sub, std::optional<schema_version> opt_ver) {
schema_version ver;
// Ensure the subject exists
auto versions = co_await get_versions(sub, include_deleted::no);
if (opt_ver.has_value()) {
ver = *opt_ver;
auto version_not_found = std::none_of(
versions.begin(), versions.end(), [ver](auto const& v) {
return ver == v;
});
if (version_not_found) {
throw as_exception(not_found(sub, ver));
}
} else {
auto versions = co_await get_versions(sub, include_deleted::no);
vassert(
!versions.empty(), "get_versions should not return empty versions");
ver = versions.back();
Expand Down
14 changes: 14 additions & 0 deletions tests/rptest/tests/schema_registry_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1244,6 +1244,20 @@ def test_protobuf(self):
assert result_raw.status_code == requests.codes.ok
assert result_raw.json() == [2]

# invalid subject should error with 40401
result_raw = self._get_subjects_subject_versions_version_referenced_by(
"invalid_subject", 1)
self.logger.info(result_raw)
assert result_raw.status_code == requests.codes.not_found
assert result_raw.json()["error_code"] == 40401

# invalid version should error with 40402
result_raw = self._get_subjects_subject_versions_version_referenced_by(
"simple", 2)
self.logger.info(result_raw)
assert result_raw.status_code == requests.codes.not_found
assert result_raw.json()["error_code"] == 40402

@cluster(num_nodes=4)
@parametrize(protocol=SchemaType.AVRO, client_type=SerdeClientType.Python)
@parametrize(protocol=SchemaType.AVRO, client_type=SerdeClientType.Java)
Expand Down

0 comments on commit 64f56c5

Please sign in to comment.