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 value in URL is irreversible in Admin #257

Closed
PetrDlouhy opened this issue Oct 28, 2018 · 6 comments
Closed

Wrong value in URL is irreversible in Admin #257

PetrDlouhy opened this issue Oct 28, 2018 · 6 comments
Labels

Comments

@PetrDlouhy
Copy link
Contributor

I filled template-addons' value in TemplateItem URL field and enabled URL as Pattern. It resulted in broken admin, so I couldn't correct the value without using console (which is quite severe, because it could lead to long downtime, if the user editing hadn't the ability to use console).
The wrong value also broke the page where the menu was rendered (which I consider much less severe bug, because if I was able to edit it in admin I could fix it immediately).

The error is following:

Traceback (most recent call last):
  File "/lib/python3.6/site-packages/django/core/handlers/exception.py", line 35, in inner
    response = get_response(request)
  File "/lib/python3.6/site-packages/django/core/handlers/base.py", line 119, in _get_response
    response = middleware_method(request, callback, callback_args, callback_kwargs)
  File "/lib/python3.6/site-packages/debug_toolbar/middleware.py", line 84, in process_view
    response = panel.process_view(request, view_func, view_args, view_kwargs)
  File "/lib/python3.6/site-packages/debug_toolbar/panels/profiling.py", line 155, in process_view
    return self.profiler.runcall(view_func, *args, **view_kwargs)
  File "/usr/lib/python3.6/cProfile.py", line 109, in runcall
    return func(*args, **kw)
  File "/lib/python3.6/site-packages/django/utils/decorators.py", line 142, in _wrapped_view
    response = view_func(request, *args, **kwargs)
  File "/lib/python3.6/site-packages/django/views/decorators/cache.py", line 44, in _wrapped_view_func
    response = view_func(request, *args, **kwargs)
  File "/lib/python3.6/site-packages/django/contrib/admin/sites.py", line 223, in inner
    return view(request, *args, **kwargs)
  File "/lib/python3.6/site-packages/sitetree/admin.py", line 222, in item_edit
    return self.change_view(request, item_id, extra_context={'tree': tree})
  File "/lib/python3.6/site-packages/django/contrib/admin/options.py", line 1557, in change_view
    return self.changeform_view(request, object_id, form_url, extra_context)
  File "/lib/python3.6/site-packages/django/utils/decorators.py", line 62, in _wrapper
    return bound_func(*args, **kwargs)
  File "/lib/python3.6/site-packages/django/utils/decorators.py", line 142, in _wrapped_view
    response = view_func(request, *args, **kwargs)
  File "/lib/python3.6/site-packages/django/utils/decorators.py", line 58, in bound_func
    return func.__get__(self, type(self))(*args2, **kwargs2)
  File "/lib/python3.6/site-packages/django/contrib/admin/options.py", line 1451, in changeform_view
    return self._changeform_view(request, object_id, form_url, extra_context)
  File "/lib/python3.6/site-packages/django/contrib/admin/options.py", line 1480, in _changeform_view
    ModelForm = self.get_form(request, obj)
  File "/lib/python3.6/site-packages/sitetree/admin.py", line 173, in get_form
    my_choice_field = TreeItemChoiceField(self.tree, initial=previous_parent_id)
  File "/lib/python3.6/site-packages/sitetree/fields.py", line 38, in __init__
    self.choices = self._build_choices()
  File "/lib/python3.6/site-packages/sitetree/fields.py", line 50, in _build_choices
    ).render(context)
  File "/lib/python3.6/site-packages/sitetree/templatetags/sitetree.py", line 164, in render
    tree_items = get_sitetree().tree(self.tree_alias, context)
  File "/lib/python3.6/site-packages/sitetree/sitetreeapp.py", line 953, in tree
    tree_alias, sitetree_items = self.init_tree(tree_alias, context)
  File "/lib/python3.6/site-packages/sitetree/sitetreeapp.py", line 732, in init_tree
    tree_alias, sitetree_items = self.get_sitetree(tree_alias)
  File "/lib/python3.6/site-packages/sitetree/sitetreeapp.py", line 567, in get_sitetree
    item.url_resolved = url(item)
  File "/lib/python3.6/site-packages/sitetree/sitetreeapp.py", line 697, in url
    Token(token_type=TOKEN_BLOCK, contents=url_token)
  File "/lib/python3.6/site-packages/django/template/defaulttags.py", line 1381, in url
    args.append(parser.compile_filter(value))
  File "/lib/python3.6/site-packages/django/template/base.py", line 568, in compile_filter
    return FilterExpression(token, self)
  File "/lib/python3.6/site-packages/django/template/base.py", line 668, in __init__
    "from '%s'" % (token[upto:], token))
django.template.exceptions.TemplateSyntaxError: Could not parse the remainder: ''' from '''
@idlesign
Copy link
Owner

idlesign commented Oct 28, 2018

It resulted in broken admin [...]

Thank you for the report.
Sitetree specialcases admin app, and unless there's a regression, wrong url shourd not lead to a total break. Moreover sitetree has SITETREE_ADMIN_APP_NAME setting for custom admin apps.

Do you use a custom admin app?
Do you use recent sitetree?

@PetrDlouhy
Copy link
Contributor Author

@idlesign I use django-sitetree==1.12.0 and I don't use any custom admin app (as far as I know). I tried to investigate further, and the problem occurs only with the ' sign and not with other pattern errors.
Currently I am trying to write PR with test and fix for this.

@idlesign
Copy link
Owner

Then you may want to check current_app_is_admin functions properly.
https://github.com/idlesign/django-sitetree/blob/master/sitetree/sitetreeapp.py#L472

PetrDlouhy added a commit to PetrDlouhy/django-sitetree that referenced this issue Oct 28, 2018
@PetrDlouhy
Copy link
Contributor Author

@idlesign Now I am sure, that it is bug in django-sitetree. In #258 you have test, that fails if the fix there is removed.

PetrDlouhy added a commit to PetrDlouhy/django-sitetree that referenced this issue Oct 30, 2018
PetrDlouhy added a commit to PetrDlouhy/django-sitetree that referenced this issue Oct 30, 2018
@PetrDlouhy
Copy link
Contributor Author

Simple steps to reproduce:

  1. Run demo app admin
  2. Create new item in tree demo
  3. Fill in following parameters: Title: Foo, URL: foo', URL as pattern: True
  4. You can't take your edit back and the main demo page is broken.

@idlesign
Copy link
Owner

Seems to be fixed in master by #290
Again thank you for the report and sorry for those two years.

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

Successfully merging a pull request may close this issue.

2 participants