Skip to content

Commit

Permalink
fix: handle InMemoryDatabase find_schemas latest when no versions ava…
Browse files Browse the repository at this point in the history
…ilable for subject
  • Loading branch information
biggusdonzus committed Mar 7, 2024
1 parent af21074 commit c382270
Show file tree
Hide file tree
Showing 2 changed files with 14 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
13 changes: 13 additions & 0 deletions tests/unit/test_in_memory_database.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"""
Copyright (c) 2024 Aiven Ltd
See LICENSE for details
"""
from karapace.in_memory_database import InMemoryDatabase, Subject


def test_find_schemas() -> 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 c382270

Please sign in to comment.