Skip to content

Commit

Permalink
Merge pull request #835 from Aiven-Open/fdorlandi-sentry-list-index-o…
Browse files Browse the repository at this point in the history
…ut-of-range

fix: handle InMemoryDatabase find_schemas latest when no versions available for subject
  • Loading branch information
aiven-anton authored Mar 8, 2024
2 parents af21074 + 8f6562a commit ea3300d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion karapace/in_memory_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def find_schemas(self, *, include_deleted: bool, latest_only: bool) -> dict[Subj
for subject, subject_data in self.subjects.items():
selected_schemas: list[SchemaVersion] = []
schemas = list(subject_data.schemas.values())
if latest_only:
if latest_only and len(schemas) > 0:
# TODO don't include the deleted here?
selected_schemas = [schemas[-1]]
else:
Expand Down
14 changes: 14 additions & 0 deletions tests/unit/test_in_memory_database.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"""
Copyright (c) 2024 Aiven Ltd
See LICENSE for details
"""
from karapace.in_memory_database import InMemoryDatabase, Subject


class TestFindSchemas:
def test_returns_empty_list_when_no_schemas(self) -> None:
database = InMemoryDatabase()
subject = Subject("hello_world")
database.insert_subject(subject=subject)
expected = {subject: []}
assert database.find_schemas(include_deleted=True, latest_only=True) == expected

0 comments on commit ea3300d

Please sign in to comment.