Skip to content

Commit

Permalink
fix: IndexError: negative indexes not allowed
Browse files Browse the repository at this point in the history
* IndexError: negative indexes are not accepted by SQL index / slice
  operators

* sqlalchemy >= 2.0.0 removed the possibility to have negative indices
  • Loading branch information
utnapischtim committed Dec 5, 2024
1 parent 03f6186 commit 0d41da1
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions invenio_records/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ def revert(self, revision_id):
if self.model is None:
raise MissingModelError()

revision = self.revisions[revision_id]
revision = list(self.revisions)[revision_id]

with db.session.begin_nested():
if self.send_signals:
Expand Down Expand Up @@ -635,7 +635,7 @@ def __getitem__(self, revision_id):
instances having to be updated.)
"""
if revision_id < 0:
return RecordRevision(self.model.versions[revision_id])
return RecordRevision(list(self.model.versions)[revision_id])
try:
return RecordRevision(
self.model.versions.filter_by(version_id=revision_id + 1).one()
Expand All @@ -654,4 +654,9 @@ def __contains__(self, revision_id):
def __reversed__(self):
"""Allows to use reversed operator."""
for version_index in range(self.model.versions.count()):
yield RecordRevision(self.model.versions[-(version_index + 1)])
versions = (
list(self.model.versions)
if -(version_index + 1) < 0
else self.model.versions
)
yield RecordRevision(versions[-(version_index + 1)])

0 comments on commit 0d41da1

Please sign in to comment.