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

Django 1.11 and AttributeError: Can only be accessed via an instance when creating a new Topic #69

Closed
smclenithan opened this issue Jun 7, 2017 · 2 comments

Comments

@smclenithan
Copy link

It would seem that after upgrading to Django 1.11 I am getting this error at this point:

raise AttributeError(_('Can only be accessed via an instance.'))

[07/Jun/2017 14:16:29] ERROR [django.request:135] Internal Server Error: /forum/forum/test-forum-77/topic/create/
Traceback (most recent call last):
  File "/opt/pyenv/versions/3.6.1/lib/python3.6/site-packages/django/core/handlers/exception.py", line 41, in inner
    response = get_response(request)
  File "/opt/pyenv/versions/3.6.1/lib/python3.6/site-packages/django/core/handlers/base.py", line 249, in _legacy_get_response
    response = self._get_response(request)
  File "/opt/pyenv/versions/3.6.1/lib/python3.6/site-packages/django/core/handlers/base.py", line 187, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/opt/pyenv/versions/3.6.1/lib/python3.6/site-packages/django/core/handlers/base.py", line 185, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/opt/pyenv/versions/3.6.1/lib/python3.6/contextlib.py", line 53, in inner
    return func(*args, **kwds)
  File "/opt/pyenv/versions/3.6.1/lib/python3.6/contextlib.py", line 53, in inner
    return func(*args, **kwds)
  File "/opt/pyenv/versions/3.6.1/lib/python3.6/contextlib.py", line 53, in inner
    return func(*args, **kwds)
  [Previous line repeated 1 more times]
  File "/opt/pyenv/versions/3.6.1/lib/python3.6/site-packages/django/views/generic/base.py", line 68, in view
    return self.dispatch(request, *args, **kwargs)
  File "/opt/pyenv/versions/3.6.1/lib/python3.6/site-packages/machina/apps/forum_permission/viewmixins.py", line 108, in dispatch
    return super(PermissionRequiredMixin, self).dispatch(request, *args, **kwargs)
  File "/opt/pyenv/versions/3.6.1/lib/python3.6/site-packages/django/views/generic/base.py", line 88, in dispatch
    return handler(request, *args, **kwargs)
  File "/opt/pyenv/versions/3.6.1/lib/python3.6/site-packages/machina/apps/forum_conversation/views.py", line 548, in post
    return super(TopicCreateView, self).post(request, *args, **kwargs)
  File "/opt/pyenv/versions/3.6.1/lib/python3.6/site-packages/machina/apps/forum_conversation/views.py", line 434, in post
    poll_options_validated=poll_options_validated)
  File "/opt/pyenv/versions/3.6.1/lib/python3.6/site-packages/machina/apps/forum_conversation/views.py", line 494, in form_valid
    post_form, attachment_formset, poll_option_formset=poll_option_formset, **kwargs)
  File "/opt/pyenv/versions/3.6.1/lib/python3.6/site-packages/machina/apps/forum_conversation/views.py", line 348, in form_valid
    self.forum_post = post_form.save()
  File "/opt/pyenv/versions/3.6.1/lib/python3.6/site-packages/machina/apps/forum_conversation/forms.py", line 204, in save
    return super(TopicForm, self).save(commit)
  File "/opt/pyenv/versions/3.6.1/lib/python3.6/site-packages/machina/apps/forum_conversation/forms.py", line 108, in save
    post.save()
  File "/opt/pyenv/versions/3.6.1/lib/python3.6/site-packages/machina/apps/forum_conversation/abstract_models.py", line 304, in save
    super(AbstractPost, self).save(*args, **kwargs)
  File "/opt/pyenv/versions/3.6.1/lib/python3.6/site-packages/django/db/models/base.py", line 806, in save
    force_update=force_update, update_fields=update_fields)
  File "/opt/pyenv/versions/3.6.1/lib/python3.6/site-packages/django/db/models/base.py", line 831, in save_base
    update_fields=update_fields,
  File "/opt/pyenv/versions/3.6.1/lib/python3.6/site-packages/django/dispatch/dispatcher.py", line 193, in send
    for receiver in self._live_receivers(sender)
  File "/opt/pyenv/versions/3.6.1/lib/python3.6/site-packages/django/dispatch/dispatcher.py", line 193, in <listcomp>
    for receiver in self._live_receivers(sender)
  File "/opt/pyenv/versions/3.6.1/lib/python3.6/site-packages/machina/apps/forum_member/receivers.py", line 31, in increase_posts_count
    profile, dummy = ForumProfile.objects.get_or_create(user=instance.poster)
  File "/opt/pyenv/versions/3.6.1/lib/python3.6/site-packages/django/db/models/manager.py", line 85, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/opt/pyenv/versions/3.6.1/lib/python3.6/site-packages/django/db/models/query.py", line 459, in get_or_create
    lookup, params = self._extract_model_params(defaults, **kwargs)
  File "/opt/pyenv/versions/3.6.1/lib/python3.6/site-packages/django/db/models/query.py", line 521, in _extract_model_params
    property_names = self.model._meta._property_names
  File "/opt/pyenv/versions/3.6.1/lib/python3.6/site-packages/django/utils/functional.py", line 35, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/opt/pyenv/versions/3.6.1/lib/python3.6/site-packages/django/db/models/options.py", line 887, in _property_names
    dir(self.model) if isinstance(getattr(self.model, attr), property)
  File "/opt/pyenv/versions/3.6.1/lib/python3.6/site-packages/django/db/models/options.py", line 887, in <setcomp>
    dir(self.model) if isinstance(getattr(self.model, attr), property)
  File "/opt/pyenv/versions/3.6.1/lib/python3.6/site-packages/machina/models/fields.py", line 112, in __get__
    raise AttributeError(_('Can only be accessed via an instance.'))
@ellmetha
Copy link
Owner

ellmetha commented Jun 7, 2017

@smclenithan the problem only affects Django 1.11.2 if I am correct. There is a PR fixing this (#66) that I'll review soon. A new version should be released after that 😉

@smclenithan
Copy link
Author

Fantastic, Yes it seems I jumped directly to 1.11.2. I didn't even see that that PR.

@ellmetha ellmetha closed this as completed Jun 8, 2017
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

2 participants