django-cms/djangocms-link

AttributeError: 'Page' object has no attribute 'site'

sq9mev opened this issue · 4 comments

After upgrade 2.5.0 → 2.6.0:

/home/users/bociek/projects/myproject/eggs/djangocms_link-2.6.0-py3.8.egg/djangocms_link/cms_plugins.py:58: DontUsePageAttributeWarning: Don't use the page attribute on CMSPlugins! CMSPlugins are not guaranteed to have a page associated with them!
  if obj and obj.page and obj.page.site:
Internal Server Error: /pl/admin/cms/page/edit-plugin/15459/
Traceback (most recent call last):
  File "/home/users/bociek/projects/myproject/eggs/Django-2.2.9-py3.8.egg/django/core/handlers/exception.py", line 34, in inner
    response = get_response(request)
  File "/home/users/bociek/projects/myproject/eggs/Django-2.2.9-py3.8.egg/django/core/handlers/base.py", line 115, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/home/users/bociek/projects/myproject/eggs/Django-2.2.9-py3.8.egg/django/core/handlers/base.py", line 113, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/usr/lib64/python3.8/contextlib.py", line 75, in inner
    return func(*args, **kwds)
  File "/home/users/bociek/projects/myproject/eggs/Django-2.2.9-py3.8.egg/django/utils/decorators.py", line 142, in _wrapped_view
    response = view_func(request, *args, **kwargs)
  File "/home/users/bociek/projects/myproject/eggs/Django-2.2.9-py3.8.egg/django/views/decorators/cache.py", line 44, in _wrapped_view_func
    response = view_func(request, *args, **kwargs)
  File "/home/users/bociek/projects/myproject/eggs/Django-2.2.9-py3.8.egg/django/contrib/admin/sites.py", line 223, in inner
    return view(request, *args, **kwargs)
  File "/home/users/bociek/projects/myproject/eggs/Django-2.2.9-py3.8.egg/django/views/decorators/clickjacking.py", line 33, in wrapped_view
    resp = view_func(*args, **kwargs)
  File "/home/users/bociek/projects/myproject/eggs/django_cms-3.7.1-py3.8.egg/cms/admin/placeholderadmin.py", line 568, in edit_plugin
    response = plugin_instance.change_view(request, str(plugin_id))
  File "/home/users/bociek/projects/myproject/eggs/Django-2.2.9-py3.8.egg/django/contrib/admin/options.py", line 1648, in change_view
    return self.changeform_view(request, object_id, form_url, extra_context)
  File "/home/users/bociek/projects/myproject/eggs/Django-2.2.9-py3.8.egg/django/utils/decorators.py", line 45, in _wrapper
    return bound_method(*args, **kwargs)
  File "/home/users/bociek/projects/myproject/eggs/Django-2.2.9-py3.8.egg/django/utils/decorators.py", line 142, in _wrapped_view
    response = view_func(request, *args, **kwargs)
  File "/home/users/bociek/projects/myproject/eggs/Django-2.2.9-py3.8.egg/django/contrib/admin/options.py", line 1529, in changeform_view
    return self._changeform_view(request, object_id, form_url, extra_context)
  File "/home/users/bociek/projects/myproject/eggs/Django-2.2.9-py3.8.egg/django/contrib/admin/options.py", line 1562, in _changeform_view
    ModelForm = self.get_form(request, obj, change=not add)
  File "/home/users/bociek/projects/myproject/eggs/djangocms_link-2.6.0-py3.8.egg/djangocms_link/cms_plugins.py", line 58, in get_form
    if obj and obj.page and obj.page.site:
AttributeError: 'Page' object has no attribute 'site'

Yes, it's a bug in 2.6, rolling back to 2.5 resolved it for me.

@FinalAngel, perhaps we can push a rollback to pypi or a quick fix?

Few details:

The link can be created normally, but this error appears in the editing iframe on an attempt to edit it.

One developer reported that it doesn't appear in static placeholders.

A project example that was affected after 2.6 upgrade - https://gitlab.com/what-digital/djangocms-template/

Probably it happened after removing try/except block