Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

id-based pagination throws exception if no entries match #217

Closed
fluffy-critter opened this issue Jun 27, 2019 · 0 comments

Comments

Projects
None yet
1 participant
@fluffy-critter
Copy link
Collaborator

commented Jun 27, 2019

Expected Behavior

If a category page is requested with a bogus pagination id, it should either return 404 or provide a blank view

Current Behavior

Exception thrown:

Traceback (most recent call last):
  File "/Users/jshagam/.local/share/virtualenvs/Publ-jIbESq8L/lib/python3.7/site-packages/pony/orm/core.py", line 5576, in extract_vars
    try: value = extractor(globals, locals)
  File "/Users/jshagam/.local/share/virtualenvs/Publ-jIbESq8L/lib/python3.7/site-packages/pony/orm/asttranslation.py", line 370, in extractor
    return eval(code, globals, locals)
  File "ref.id", line 1, in <module>
    # queries.py
AttributeError: 'NoneType' object has no attribute 'id'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/jshagam/.local/share/virtualenvs/Publ-jIbESq8L/lib/python3.7/site-packages/flask/app.py", line 2309, in __call__
    return self.wsgi_app(environ, start_response)
  File "/Users/jshagam/.local/share/virtualenvs/Publ-jIbESq8L/lib/python3.7/site-packages/flask/app.py", line 2295, in wsgi_app
    response = self.handle_exception(e)
  File "/Users/jshagam/.local/share/virtualenvs/Publ-jIbESq8L/lib/python3.7/site-packages/flask/app.py", line 1741, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/Users/jshagam/.local/share/virtualenvs/Publ-jIbESq8L/lib/python3.7/site-packages/flask/_compat.py", line 35, in reraise
    raise value
  File "/Users/jshagam/.local/share/virtualenvs/Publ-jIbESq8L/lib/python3.7/site-packages/flask/app.py", line 2292, in wsgi_app
    response = self.full_dispatch_request()
  File "/Users/jshagam/.local/share/virtualenvs/Publ-jIbESq8L/lib/python3.7/site-packages/flask/app.py", line 1815, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/Users/jshagam/.local/share/virtualenvs/Publ-jIbESq8L/lib/python3.7/site-packages/flask/app.py", line 1718, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/Users/jshagam/.local/share/virtualenvs/Publ-jIbESq8L/lib/python3.7/site-packages/flask/_compat.py", line 35, in reraise
    raise value
  File "/Users/jshagam/.local/share/virtualenvs/Publ-jIbESq8L/lib/python3.7/site-packages/flask/app.py", line 1813, in full_dispatch_request
    rv = self.dispatch_request()
  File "/Users/jshagam/.local/share/virtualenvs/Publ-jIbESq8L/lib/python3.7/site-packages/flask/app.py", line 1799, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "<string>", line 2, in render_category
    """ Rendering functions """
  File "/Users/jshagam/.local/share/virtualenvs/Publ-jIbESq8L/lib/python3.7/site-packages/pony/orm/core.py", line 528, in new_func
    result = func(*args, **kwargs)
  File "/Users/jshagam/projects/Publ/publ/rendering.py", line 293, in render_category
    view=view_obj)
  File "/Users/jshagam/projects/Publ/publ/rendering.py", line 135, in render_publ_template
    return do_render(template, request.args, **kwargs)
  File "/Users/jshagam/.local/share/virtualenvs/Publ-jIbESq8L/lib/python3.7/site-packages/flask_caching/__init__.py", line 779, in decorated_function
    rv = f(*args, **kwargs)
  File "/Users/jshagam/projects/Publ/publ/rendering.py", line 130, in do_render
    **kwargs
  File "/Users/jshagam/.local/share/virtualenvs/Publ-jIbESq8L/lib/python3.7/site-packages/flask/templating.py", line 135, in render_template
    context, ctx.app)
  File "/Users/jshagam/.local/share/virtualenvs/Publ-jIbESq8L/lib/python3.7/site-packages/flask/templating.py", line 117, in _render
    rv = template.render(context)
  File "/Users/jshagam/.local/share/virtualenvs/Publ-jIbESq8L/lib/python3.7/site-packages/jinja2/asyncsupport.py", line 76, in render
    return original_render(self, *args, **kwargs)
  File "/Users/jshagam/.local/share/virtualenvs/Publ-jIbESq8L/lib/python3.7/site-packages/jinja2/environment.py", line 1008, in render
    return self.environment.handle_exception(exc_info, True)
  File "/Users/jshagam/.local/share/virtualenvs/Publ-jIbESq8L/lib/python3.7/site-packages/jinja2/environment.py", line 780, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/Users/jshagam/.local/share/virtualenvs/Publ-jIbESq8L/lib/python3.7/site-packages/jinja2/_compat.py", line 37, in reraise
    raise value.with_traceback(tb)
  File "/Users/jshagam/projects/Publ/tests/templates/index.html", line 41, in top-level template code
    {% block content %}
  File "/Users/jshagam/projects/Publ/tests/templates/index.html", line 43, in block "content"
    {% set content = view(entry_type_not='sidebar',count=20) %}
  File "/Users/jshagam/projects/Publ/publ/view.py", line 351, in __call__
    return View({**self.spec, **restrict})
  File "/Users/jshagam/projects/Publ/publ/view.py", line 90, in __init__
    spec).order_by(*ORDER_BY[self._order_by])
  File "/Users/jshagam/projects/Publ/publ/queries.py", line 216, in build_query
    query = where_entry_last(query, get_entry(spec['last']))
  File "/Users/jshagam/projects/Publ/publ/queries.py", line 95, in where_entry_last
    e for e in query
  File "/Users/jshagam/.local/share/virtualenvs/Publ-jIbESq8L/lib/python3.7/site-packages/pony/orm/core.py", line 5504, in select
    return make_query(args, frame_depth=cut_traceback_depth+1)
  File "/Users/jshagam/.local/share/virtualenvs/Publ-jIbESq8L/lib/python3.7/site-packages/pony/orm/core.py", line 5500, in make_query
    return Query(code_key, tree.code, globals, locals, cells, left_join)
  File "/Users/jshagam/.local/share/virtualenvs/Publ-jIbESq8L/lib/python3.7/site-packages/pony/orm/core.py", line 5621, in __init__
    vars, vartypes = extract_vars(code_key, filter_num, extractors, globals, locals, cells)
  File "/Users/jshagam/.local/share/virtualenvs/Publ-jIbESq8L/lib/python3.7/site-packages/pony/orm/core.py", line 5577, in extract_vars
    except Exception as cause: raise ExprEvalError(src, cause)
pony.orm.core.ExprEvalError: `ref.id` raises AttributeError: 'NoneType' object has no attribute 'id'

Steps to Reproduce (for bugs)

./runTests.sh and then load e.g. http://localhost:5000/?id=2123424

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.