Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't crash on UnrepeatableReadErrors from knowledge db #8138

Merged
merged 1 commit into from
Sep 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions src/tribler/core/database/layers/knowledge.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from pony import orm
from pony.orm import raw_sql
from pony.orm.core import Database, Entity, Query, select
from pony.orm.core import Database, Entity, Query, UnrepeatableReadError, select
from pony.utils import between

from tribler.core.database.layers.layer import EntityImpl, Layer
Expand Down Expand Up @@ -113,7 +113,7 @@ class StatementOp(EntityImpl):
updated_at: datetime.datetime
auto_generated: bool

def __init__(self, statement: Statement, peer: Peer, operation: int, clock: int, # noqa: D107, PLR0913
def __init__(self, statement: Statement, peer: Peer, operation: int, clock: int, # noqa: D107
signature: bytes, auto_generated: bool) -> None: ...

@staticmethod
Expand Down Expand Up @@ -278,7 +278,7 @@ def _get_resources(self, resource_type: ResourceType | None, name: str | None, c
results = results.filter(lambda r: r.type == resource_type.value)
return results

def get_statements(self, source_type: ResourceType | None, source_name: str | None, # noqa: PLR0913
def get_statements(self, source_type: ResourceType | None, source_name: str | None,
statements_getter: Callable[[Entity], Entity],
target_condition: Callable[[Statement], bool], condition: Callable[[Statement], bool],
case_sensitive: bool, ) -> Iterator[Statement]:
Expand Down Expand Up @@ -443,9 +443,14 @@ def get_simple_statements(self, subject_type: ResourceType | None = None, subjec
case_sensitive=case_sensitive,
)

return [SimpleStatement(subject_type=s.subject.type, subject=s.subject.name, predicate=s.object.type,
object=s.object.name)
for s in statements]
results = []
for s in statements:
try:
results.append(SimpleStatement(subject_type=s.subject.type, subject=s.subject.name,
predicate=s.object.type, object=s.object.name))
except UnrepeatableReadError as e:
self.logger.exception(e)
return results

def get_suggestions(self, subject_type: ResourceType | None = None, subject: str | None = "",
predicate: ResourceType | None = None, case_sensitive: bool = True) -> List[str]:
Expand Down