Skip to content

Commit c20403d

Browse files
committed
fix: flask-sqlalchemy.pagination >= 3.0.0
* this is a compatibility fix. the old compatibility commit was wrong. they are not interchangable
1 parent 48cb7b7 commit c20403d

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

invenio_rdm_records/oaiserver/services/services.py

+21-7
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import re
1111

1212
from flask import current_app
13+
from flask_sqlalchemy.pagination import Pagination
1314
from invenio_db import db
1415
from invenio_i18n import lazy_gettext as _
1516
from invenio_oaiserver.models import OAISet
@@ -31,12 +32,25 @@
3132
)
3233
from .uow import OAISetCommitOp, OAISetDeleteOp
3334

34-
try:
35-
# flask_sqlalchemy<3.0.0
36-
from flask_sqlalchemy import Pagination
37-
except ImportError:
38-
# flask_sqlalchemy>=3.0.0
39-
from flask_sqlalchemy.pagination import Pagination
35+
36+
class OAIPagination(Pagination):
37+
"""OAI Pagination."""
38+
39+
def _query_items(self):
40+
"""Return items."""
41+
try:
42+
return self._query_args["items"]
43+
except KeyError:
44+
msg = "items not set in OAIPaginations constructor."
45+
raise RuntimeError(msg)
46+
47+
def _query_count(self):
48+
"""Return count."""
49+
try:
50+
return self._query_args["total"]
51+
except KeyError:
52+
msg = "total not set in OAIPaginations constructor."
53+
raise RuntimeError(msg)
4054

4155

4256
class OAIPMHServerService(Service):
@@ -226,7 +240,7 @@ def read_all_formats(self, identity):
226240
for k, v in current_app.config.get("OAISERVER_METADATA_FORMATS").items()
227241
]
228242

229-
results = Pagination(
243+
results = OAIPagination(
230244
query=None,
231245
page=1,
232246
per_page=None,

0 commit comments

Comments
 (0)