P
P
pcdesign2018-03-05 10:14:48
MongoDB
pcdesign, 2018-03-05 10:14:48

How to overcome the error "OverflowError: signed integer is greater than maximum"?

Here is the documentation for flask-mongoengine
docs.mongoengine.org/projects/flask-mongoengine/en...

And there is a paragraph about pagination:

paginated_todos = Todo.objects.paginate(page=page, per_page=10)


Everything works fine, it breaks into pages.
But, if you enter some hefty number for page (for example, 220000000000), then we get an error
OverflowError: signed integer is greater than maximum


If even more, page=22000000444444444444444444444440000, then the error is
Python int too large to convert to C long

Question. Is there any way to do without
try:
     paginated_todos = Todo.objects.paginate(page=page, per_page=10)
except:
     abort(404)

?
In order not to wrap the pagination in the tray every time?

PS

Flask-SQLAlchemy - it turns out the same suffers.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Ruslan., 2018-03-05
@pcdesign

You can write a function similar to the above doc:
# Paginate through todo
def view_todos(page=1):
paginated_todos = Todo.objects.paginate(page=page, per_page=10)
And inside this function check for errors
def view_todos (page=1):
try:
return Todo.objects.paginate(page=page, per_page=10)
except:
abort(404)
And then use the view_todos function everywhere in your code, then you won't have to clone the code.
In fact, it turns out a decorator for the pagination function.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question