Skip to content

Commit

Permalink
Don't crash on UnrepeatableReadErrors from knowledge db (#8138)
Browse files Browse the repository at this point in the history
  • Loading branch information
egbertbouman authored Sep 6, 2024
2 parents d63f266 + 7672809 commit 97c4bd9
Showing 1 changed file with 11 additions and 6 deletions.
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

0 comments on commit 97c4bd9

Please sign in to comment.