Skip to content

Commit

Permalink
refactor: use inline version object
Browse files Browse the repository at this point in the history
- we create the `Version` objects in the API controller
using the `Versioner.V()` factory method, but we've moved this statement inline as an argument to the dependent functions.
This prevents us from overriding the `version` path parameter.
  • Loading branch information
nosahama committed Jun 5, 2024
1 parent 9c02e37 commit c36b130
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions karapace/schema_registry_apis.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,6 @@ async def compatibility_check(
schema_type = self._validate_schema_type(content_type=content_type, data=body)
references = self._validate_references(content_type, schema_type, body)
try:
version = Versioner.V(version)
references, new_schema_dependencies = self.schema_registry.resolve_references(references)
new_schema = ValidatedTypedSchema.parse(
schema_type=schema_type,
Expand All @@ -399,7 +398,7 @@ async def compatibility_check(
status=HTTPStatus.UNPROCESSABLE_ENTITY,
)
try:
old = self.schema_registry.subject_version_get(subject=subject, version=version)
old = self.schema_registry.subject_version_get(subject=subject, version=Versioner.V(version))
except InvalidVersion:
self._invalid_version(content_type, version)
except (VersionNotFoundException, SchemasNotFoundException, SubjectNotFoundException):
Expand Down Expand Up @@ -784,8 +783,7 @@ async def subject_version_get(

deleted = request.query.get("deleted", "false").lower() == "true"
try:
version = Versioner.V(version)
subject_data = self.schema_registry.subject_version_get(subject, version, include_deleted=deleted)
subject_data = self.schema_registry.subject_version_get(subject, Versioner.V(version), include_deleted=deleted)
if "compatibility" in subject_data:
del subject_data["compatibility"]
self.r(subject_data, content_type)
Expand Down Expand Up @@ -819,8 +817,9 @@ async def subject_version_delete(
are_we_master, master_url = await self.schema_registry.get_master()
if are_we_master:
try:
version = Versioner.V(version)
resolved_version = await self.schema_registry.subject_version_delete_local(subject, version, permanent)
resolved_version = await self.schema_registry.subject_version_delete_local(
subject, Versioner.V(version), permanent
)
self.r(str(resolved_version), content_type, status=HTTPStatus.OK)
except (SubjectNotFoundException, SchemasNotFoundException):
self.r(
Expand Down Expand Up @@ -890,8 +889,7 @@ async def subject_version_schema_get(
self._check_authorization(user, Operation.Read, f"Subject:{subject}")

try:
version = Versioner.V(version)
subject_data = self.schema_registry.subject_version_get(subject, version)
subject_data = self.schema_registry.subject_version_get(subject, Versioner.V(version))
self.r(subject_data["schema"], content_type)
except InvalidVersion:
self._invalid_version(content_type, version)
Expand All @@ -918,8 +916,7 @@ async def subject_version_referencedby_get(self, content_type, *, subject, versi
self._check_authorization(user, Operation.Read, f"Subject:{subject}")

try:
version = Versioner.V(version)
referenced_by = await self.schema_registry.subject_version_referencedby_get(subject, version)
referenced_by = await self.schema_registry.subject_version_referencedby_get(subject, Versioner.V(version))
except (SubjectNotFoundException, SchemasNotFoundException):
self.r(
body={
Expand Down

0 comments on commit c36b130

Please sign in to comment.