Skip to content

Commit 631f12e

Browse files
authored
Updating proto runtime path (#1170)
* Updating proto runtime path * Updating proto runtime path * Updating proto runtime path * Updating proto runtime path
1 parent eac5cd6 commit 631f12e

3 files changed

Lines changed: 18 additions & 10 deletions

File tree

src/karapace/kafka_rest_apis/consumer_manager.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -551,11 +551,18 @@ async def fetch(self, internal_name: tuple[str, str], content_type: str, formats
551551
try:
552552
key = await self.deserialize(msg.key(), request_format) if msg.key() else None
553553
except DeserializationError as e:
554-
KarapaceBase.unprocessable_entity(
555-
message=f"key deserialization error for format {request_format}: {e}",
556-
sub_code=RESTErrorCodes.HTTP_UNPROCESSABLE_ENTITY.value,
557-
content_type=content_type,
558-
)
554+
if request_format == "avro":
555+
LOG.warning("Cannot process non-empty key using avro deserializer, falling back to binary.")
556+
key = await self.deserialize(msg.key(), "binary")
557+
if request_format == "protobuf":
558+
LOG.warning("Cannot process non-empty key using protobuf deserializer, falling back to binary.")
559+
key = await self.deserialize(msg.key(), "binary")
560+
else:
561+
KarapaceBase.unprocessable_entity(
562+
message=f"key deserialization error for format {request_format}: {e}",
563+
sub_code=RESTErrorCodes.HTTP_UNPROCESSABLE_ENTITY.value,
564+
content_type=content_type,
565+
)
559566
try:
560567
value = await self.deserialize(msg.value(), request_format) if msg.value() else None
561568
except DeserializationError as e:

src/karapace/protobuf/io.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def get_protobuf_class_instance(
133133
cwd=work_dir,
134134
)
135135

136-
runtime_proto_path = f"./runtime/{proto_name}"
136+
runtime_proto_path = str(work_dir.resolve())
137137
if runtime_proto_path not in sys.path:
138138
# todo: This will leave residues on sys.path in case of exceptions. If really must
139139
# mutate sys.path, we should at least wrap in try-finally.

src/karapace/schema_models.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
from karapace.schema_type import SchemaType
2828
from karapace.typing import JsonObject, SchemaId, Subject, Version, VersionTag
2929
from karapace.utils import assert_never, json_decode, json_encode, JSONDecodeError
30-
from typing import Any, cast, Final, final
30+
from typing import Any, cast, Final, final, Union
3131

3232
import hashlib
3333
import logging
@@ -53,11 +53,12 @@ def parse_jsonschema_definition(schema_definition: str) -> Draft7Validator:
5353
Raises:
5454
SchemaError: If `schema_definition` is not a valid Draft7 schema.
5555
"""
56-
schema = json_decode(schema_definition)
56+
raw_schema = json_decode(schema_definition)
57+
schema = cast(Union[Mapping[str, Any], bool], raw_schema)
5758
# TODO: Annotations dictate Mapping[str, Any] here, but we have unit tests that
5859
# use bool values and fail if we assert isinstance(_, dict).
59-
Draft7Validator.check_schema(schema) # type: ignore[arg-type]
60-
return Draft7Validator(schema) # type: ignore[arg-type]
60+
Draft7Validator.check_schema(schema)
61+
return Draft7Validator(schema)
6162

6263

6364
def _format_protobuf(schema: str, dependencies: Collection[Dependency], name: str = "schema.proto") -> str:

0 commit comments

Comments
 (0)