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

Wrong navigation when descendant categories have same name #83

Open
miceno opened this issue Jul 31, 2014 · 0 comments
Open

Wrong navigation when descendant categories have same name #83

miceno opened this issue Jul 31, 2014 · 0 comments

Comments

@miceno
Copy link
Contributor

miceno commented Jul 31, 2014

I have found a bug. Let's say that you have the following taxonomy (sorry for the Spanish):

BISONTE
    CABEZA
        MORRO
        CARRILLERA
        LENGUA
        SESOS
    CUELLO
        MORRILLO
        AGUJA
        PESCUEZO
        MOLLEJAS
TORO
    CABEZA
        MORRO
        CARRILLERA
        LENGUA
        SESOS
    CUELLO
        MORRILLO
        AGUJA
        PESCUEZO
        MOLLEJAS

The second and third levels share the same names. So when you navigate to the page of a category in the third level (http://127.0.0.1:8000/categories/bisonte/cabeza/carrillera/), you get an error like:

Environment:
Request Method: GET
Request URL: http://127.0.0.1:8000/categories/bisonte/cabeza/carrillera/
Django Version: 1.6.5
Python Version: 2.7.5
Installed Applications:
('grappelli',
 'django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'categories',
 'categories.editor')
Installed Middleware:
(u'debug_toolbar.middleware.DebugToolbarMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware')

Traceback:
File "/Users/Downloads/pytesting/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  112.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/Users/Downloads/devel/project-core/core_categories/categories/views.py" in category_detail
  27.             parent__slug__iexact=path_items[-2])
File "/Users/Downloads/pytesting/lib/python2.7/site-packages/django/shortcuts/__init__.py" in get_object_or_404
  113.         return queryset.get(*args, **kwargs)
File "/Users/Downloads/pytesting/lib/python2.7/site-packages/django/db/models/query.py" in get
  313.             (self.model._meta.object_name, num))

Exception Type: MultipleObjectsReturned at /categories/bisonte/cabeza/carrillera/
Exception Value: get() returned more than one Category -- it returned 2!

The issue is that the URL for /categories/bisonte/cabeza/carrillera/ and categories/toro/cabeza/carrillera/ share the same level 2 and leve 3 slugs, so the code at category_detail fails since there are more than 1 category that meets the criteria. The code at view.py:category_detail reveals there is a hardcode search for only two levels up the category path.

Thanks to a reference at stackoverflow.com I found a solution to it. I am preparing a pull request.

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

1 participant