jackm / kijiji-manager

App for viewing, posting, reposting, and deleting your Kijiji ads
https://pypi.org/project/kijiji-manager/
MIT License
52 stars 11 forks source link

Exception/505 when visiting conversations tab #22

Closed SomeMashedPotatoes closed 2 years ago

SomeMashedPotatoes commented 3 years ago

First off, great work on this project, it was working perfectly up until I went to the conversations tab to try and view my conversations. I know that I have one conversation but I could not even view the page and I instead get a 500 page. Here is the output, looking at the logs it seems like it has to do with the jinja formatting.


127.0.0.1 - - [28/Nov/2021 01:00:38] "GET / HTTP/1.1" 302 -
127.0.0.1 - - [28/Nov/2021 01:00:38] "GET /home HTTP/1.1" 200 -
127.0.0.1 - - [28/Nov/2021 01:00:38] "GET /static/style.css HTTP/1.1" 304 -
[2021-11-28 01:00:40,590] ERROR in app: Exception on /conversations/0 [GET]
Traceback (most recent call last):
  File "C:\Users\Juman\Documents\GitHub\kijiji-manager\venv\lib\site-packages\flask\app.py", line 2073, in wsgi_app
    response = self.full_dispatch_request()
  File "C:\Users\Juman\Documents\GitHub\kijiji-manager\venv\lib\site-packages\flask\app.py", line 1518, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "C:\Users\Juman\Documents\GitHub\kijiji-manager\venv\lib\site-packages\flask\app.py", line 1516, in full_dispatch_request
    rv = self.dispatch_request()
  File "C:\Users\Juman\Documents\GitHub\kijiji-manager\venv\lib\site-packages\flask\app.py", line 1502, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
  File "C:\Users\Juman\Documents\GitHub\kijiji-manager\venv\lib\site-packages\flask_login\utils.py", line 272, in decorated_view
    return func(*args, **kwargs)
  File "C:\Users\Juman\Documents\GitHub\kijiji-manager\kijiji_manager\views\user.py", line 69, in conversations
    return render_template('conversations.html', conversations=data, page=page)
  File "C:\Users\Juman\Documents\GitHub\kijiji-manager\venv\lib\site-packages\flask\templating.py", line 147, in render_template
    return _render(
  File "C:\Users\Juman\Documents\GitHub\kijiji-manager\venv\lib\site-packages\flask\templating.py", line 128, in _render
    rv = template.render(context)
  File "C:\Users\Juman\Documents\GitHub\kijiji-manager\venv\lib\site-packages\jinja2\environment.py", line 1291, in render
    self.environment.handle_exception()
  File "C:\Users\Juman\Documents\GitHub\kijiji-manager\venv\lib\site-packages\jinja2\environment.py", line 925, in handle_exception
    raise rewrite_traceback_stack(source=source)
  File "C:\Users\Juman\Documents\GitHub\kijiji-manager\kijiji_manager\templates\conversations.html", line 1, in top-level template code
    {% extends 'layout.html' %}
  File "C:\Users\Juman\Documents\GitHub\kijiji-manager\kijiji_manager\templates\layout.html", line 38, in top-level template code
    {% block content %}{% endblock %}
  File "C:\Users\Juman\Documents\GitHub\kijiji-manager\kijiji_manager\templates\conversations.html", line 36, in block 'content'
    <td align="center">{% if item['user:user-message']['user:read'] == 'true' %}<i class="fas fa-check"></i>{% elif item['user:user-message']['user:read'] == 'false' %}<i class="fas fa-envelope">{% endif %}</i></td>
  File "C:\Users\Juman\Documents\GitHub\kijiji-manager\venv\lib\site-packages\jinja2\environment.py", line 455, in getitem
    return obj[argument]
jinja2.exceptions.UndefinedError: 'str object' has no attribute 'user:user-message'
127.0.0.1 - - [28/Nov/2021 01:00:40] "GET /conversations/0 HTTP/1.1" 500 -```
jackm commented 3 years ago

It seems that it is possible that a conversation might not contain a user message object. I'll have to now check for that before rendering the template to avoid exceptions like this.

Fixed in b3f45ab

SomeMashedPotatoes commented 3 years ago

Hmm I tried running it again with the new changes and I am getting the same error. My account does have 1 conversation with just 1 message sent on my end.

127.0.0.1 - - [28/Nov/2021 12:50:40] "GET /home HTTP/1.1" 200 -
127.0.0.1 - - [28/Nov/2021 12:50:40] "GET /static/style.css HTTP/1.1" 304 -
[2021-11-28 12:50:42,473] ERROR in app: Exception on /conversations/0 [GET]
Traceback (most recent call last):
  File "C:\Users\Juman\Documents\GitHub\kijiji-manager\venv\lib\site-packages\flask\app.py", line 2073, in wsgi_app
    response = self.full_dispatch_request()
  File "C:\Users\Juman\Documents\GitHub\kijiji-manager\venv\lib\site-packages\flask\app.py", line 1518, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "C:\Users\Juman\Documents\GitHub\kijiji-manager\venv\lib\site-packages\flask\app.py", line 1516, in full_dispatch_request
    rv = self.dispatch_request()
  File "C:\Users\Juman\Documents\GitHub\kijiji-manager\venv\lib\site-packages\flask\app.py", line 1502, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
  File "C:\Users\Juman\Documents\GitHub\kijiji-manager\venv\lib\site-packages\flask_login\utils.py", line 272, in decorated_view
    return func(*args, **kwargs)
  File "C:\Users\Juman\Documents\GitHub\kijiji-manager\kijiji_manager\views\user.py", line 69, in conversations
    return render_template('conversations.html', conversations=data, page=page)
  File "C:\Users\Juman\Documents\GitHub\kijiji-manager\venv\lib\site-packages\flask\templating.py", line 147, in render_template
    return _render(
  File "C:\Users\Juman\Documents\GitHub\kijiji-manager\venv\lib\site-packages\flask\templating.py", line 128, in _render
    rv = template.render(context)
  File "C:\Users\Juman\Documents\GitHub\kijiji-manager\venv\lib\site-packages\jinja2\environment.py", line 1291, in render
    self.environment.handle_exception()
  File "C:\Users\Juman\Documents\GitHub\kijiji-manager\venv\lib\site-packages\jinja2\environment.py", line 925, in handle_exception
    raise rewrite_traceback_stack(source=source)
  File "C:\Users\Juman\Documents\GitHub\kijiji-manager\kijiji_manager\templates\conversations.html", line 1, in top-level template code
    {% extends 'layout.html' %}
  File "C:\Users\Juman\Documents\GitHub\kijiji-manager\kijiji_manager\templates\layout.html", line 38, in top-level template code
    {% block content %}{% endblock %}
  File "C:\Users\Juman\Documents\GitHub\kijiji-manager\kijiji_manager\templates\conversations.html", line 42, in block 'content'
    {% if item['user:user-message']['user:read'] == 'true' %}
  File "C:\Users\Juman\Documents\GitHub\kijiji-manager\venv\lib\site-packages\jinja2\environment.py", line 455, in getitem
    return obj[argument]
jinja2.exceptions.UndefinedError: 'str object' has no attribute 'user:user-message'
127.0.0.1 - - [28/Nov/2021 12:50:42] "GET /conversations/0 HTTP/1.1" 500 -
jackm commented 3 years ago

I understand what's happening now. It's because you have just a single conversation with your account. I never encounted this before because I've always had more than one conversation to display.

Try using commit fc66af2 and see if that fixes the bug.

jackm commented 2 years ago

Fixed in commit fc66af2