Skip to content

Commit

Permalink
Merge pull request Aiven-Open#924 from Aiven-Open/nosahama/EC-393/fix…
Browse files Browse the repository at this point in the history
…-version-int-log-formatting

fix: `Version` int log formatting in `schema_reader.py`
  • Loading branch information
eliax1996 authored Jul 25, 2024
2 parents 89d50c8 + 2e4572b commit 8c50eb0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
2 changes: 1 addition & 1 deletion karapace/schema_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ def _handle_msg_schema_hard_delete(self, key: dict) -> None:
if self.database.find_subject(subject=subject) is None:
LOG.warning("Hard delete: Subject %s did not exist, should have", subject)
elif version not in self.database.find_subject_schemas(subject=subject, include_deleted=True):
LOG.warning("Hard delete: Version %d for subject %s did not exist, should have", version, subject)
LOG.warning("Hard delete: version: %r for subject: %r did not exist, should have", version, subject)
else:
LOG.info("Hard delete: subject: %r version: %r", subject, version)
self.database.delete_subject_schema(subject=subject, version=version)
Expand Down
28 changes: 27 additions & 1 deletion tests/unit/test_schema_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
See LICENSE for details
"""

from _pytest.logging import LogCaptureFixture
from concurrent.futures import ThreadPoolExecutor
from confluent_kafka import Message
from dataclasses import dataclass
Expand All @@ -20,12 +21,13 @@
OFFSET_EMPTY,
OFFSET_UNINITIALIZED,
)
from karapace.typing import SchemaId
from karapace.typing import SchemaId, Version
from tests.base_testcase import BaseTestCase
from unittest.mock import Mock

import confluent_kafka
import json
import logging
import pytest
import random
import time
Expand Down Expand Up @@ -292,3 +294,27 @@ def test_soft_deleted_schema_storing() -> None:

soft_deleted_stored_schema = schema_reader.database.find_schema(schema_id=SchemaId(1))
assert soft_deleted_stored_schema is not None


def test_handle_msg_delete_subject_logs(caplog: LogCaptureFixture) -> None:
database_mock = Mock(spec=InMemoryDatabase)
database_mock.find_subject.return_value = True
database_mock.find_subject_schemas.return_value = {
Version(1): "SchemaVersion"
} # `SchemaVersion` is an actual object, simplified for test
schema_reader = KafkaSchemaReader(
config=DEFAULTS,
offset_watcher=OffsetWatcher(),
key_formatter=KeyFormatter(),
master_coordinator=None,
database=database_mock,
)

with caplog.at_level(logging.WARNING, logger="karapace.schema_reader"):
schema_reader._handle_msg_schema_hard_delete( # pylint: disable=protected-access
key={"subject": "test-subject", "version": 2}
)
for log in caplog.records:
assert log.name == "karapace.schema_reader"
assert log.levelname == "WARNING"
assert log.message == "Hard delete: version: Version(2) for subject: 'test-subject' did not exist, should have"

0 comments on commit 8c50eb0

Please sign in to comment.