From 0d41da181f0c9f5cdfe789b080a844dd21bed19e Mon Sep 17 00:00:00 2001 From: Christoph Ladurner Date: Thu, 5 Dec 2024 13:57:41 +0100 Subject: [PATCH] fix: IndexError: negative indexes not allowed * IndexError: negative indexes are not accepted by SQL index / slice operators * sqlalchemy >= 2.0.0 removed the possibility to have negative indices --- invenio_records/api.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/invenio_records/api.py b/invenio_records/api.py index 0fce2bb0..c19de11e 100644 --- a/invenio_records/api.py +++ b/invenio_records/api.py @@ -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: @@ -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() @@ -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)])