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

no_reverse_match error where django username is an email address #198

Open
thclark opened this issue Jun 13, 2019 · 3 comments
Open

no_reverse_match error where django username is an email address #198

thclark opened this issue Jun 13, 2019 · 3 comments

Comments

@thclark
Copy link

thclark commented Jun 13, 2019

Summary

If the django user model is modified such that the email address is treated as a username, the entries_by_author route cannot find a reverse match, resulting in server error.

Here are the places where entries_by_author are defined and used in puput.

Error details

Here is how to do django auth with an email username, if you wish to reproduce the error. Alternatively it might be possible to reproduce by setting an email address as a django username.

The abridged error is as follows:

ERROR 2019-06-13 13:11:12,433 log 98761 123145480708096 Internal Server Error: /blog/
Traceback (most recent call last):

[ ... blah massive stacktrace ... ]

  File "/Users/thc29/.pyenv/versions/tpast/lib/python3.6/site-packages/wagtail/contrib/routable_page/templatetags/wagtailroutablepage_tags.py", line 22, in routablepageurl
    routed_url = page.reverse_subpage(url_name, args=args, kwargs=kwargs)
  File "/Users/thc29/.pyenv/versions/tpast/lib/python3.6/site-packages/wagtail/contrib/routable_page/models.py", line 85, in reverse_subpage
    return self.get_resolver().reverse(name, *args, **kwargs)
  File "/Users/thc29/.pyenv/versions/tpast/lib/python3.6/site-packages/django/urls/resolvers.py", line 555, in reverse
    return self._reverse_with_prefix(lookup_view, '', *args, **kwargs)
  File "/Users/thc29/.pyenv/versions/tpast/lib/python3.6/site-packages/django/urls/resolvers.py", line 622, in _reverse_with_prefix
    raise NoReverseMatch(msg)
django.urls.exceptions.NoReverseMatch: Reverse for 'entries_by_author' with arguments '('[email protected]',)' not found. 1 pattern(s) tried: ['author/(?P<author>\\w+)/$']
[13/Jun/2019 13:11:12] "GET /blog/ HTTP/1.1" 500 234407

Not sure about this

I put the pattern author/(?P<author>\\w+)/$ into regex101 and it doesn't match any of the possible inputs I can think of - usernames, email addresses, or tuples as set in this argument (like ('[email protected]',)). So not sure how this works for anybody else either?

Workaround

Override the entry_links.html template (I copied it from puput/templates to myapp/templates/puput) to remove the entries by author link:

{% load wagtailroutablepage_tags puput_tags %}

<ul class="links">
{#    <li>#}
{#        <i class="fa fa-user"></i>#}
{#        <a href="{% routablepageurl blog_page 'entries_by_author' entry.owner.username %}">#}
{#            {{ entry.owner.username }}#}
{#        </a>#}
{#    </li>#}
    <li>
        <i class="fa fa-calendar"></i>
        {{ entry.date|date:"DATE_FORMAT" }}
    </li>
    {% if entry.categories.count > 0 %}
        <li>
            <i class="fa fa-folder-open"></i>
            {% categories_list entry.categories %}
        </li>
    {% endif %}
    {% if entry.tags.count > 0 %}
        <li>
            <i class="fa fa-tag"></i>
            {% tags_list blog_page.num_tags_entry_header entry.tags %}
        </li>
    {% endif %}
    {% if blog_page.display_comments %}
        <li>
            <i class="fa fa-comments"></i>
            {{ entry.num_comments }}
        </li>
    {% endif %}
</ul>

Long Term Solution

Probably the best solution is to adjust the route as per the accepted answer here, since an invalid username in the URL shouldn't bring the server to its knees:
https://stackoverflow.com/questions/32395062/django-urlpattern-for-username

@marctc
Copy link
Collaborator

marctc commented Jun 13, 2019

Take a look at this: #122

@thclark
Copy link
Author

thclark commented Jun 13, 2019

Yup, v. similar issue

@sodevious
Copy link

for anyone still having this issue, this comment helped me resolve:
#160 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants