Skip to content

decorator does not work #6

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

Closed
fxdgear opened this issue Dec 31, 2018 · 17 comments · Fixed by #16
Closed

decorator does not work #6

fxdgear opened this issue Dec 31, 2018 · 17 comments · Fixed by #16
Labels

Comments

@fxdgear
Copy link

fxdgear commented Dec 31, 2018

Using class based views I get the following error:

'MyPostDetailView' object has no attribute 'scheme'

http://dpaste.com/0KNM2VJ

@daneah
Copy link
Member

daneah commented Jan 1, 2019

@fxdgear thanks for filing this issue! I'm surprised at the error, because the method is expecting an HttpRequest object but is receiving a view object. This isn't an issue I've run into yet, so my initial suspicion is a version/configuration mismatch. Can you please provide the Django version you're using, and whether you're using the MIDDLEWARE setting or the MIDDLEWARE_CLASSES setting? If you have time, an example of the code where you're using the decorator would be helpful as well!

@daneah daneah added the bug label Jan 1, 2019
@fxdgear
Copy link
Author

fxdgear commented Jan 1, 2019

My versions are included in the dpaste.

It might be a version mismatch, but I ended up forking your project and vendoring it into my site.

Once I get complete I will try to submit a PR back.

I’ve added a fair bit of functionality and expanded on what you’ve done.

Thanks for making this project

@daneah
Copy link
Member

daneah commented Jan 1, 2019

Hmm, I didn't see the versions in the dpaste when I looked, and it's now expired. Sorry about that! I appreciate your time, I'm happy to incorporate a PR!

@fxdgear
Copy link
Author

fxdgear commented Jan 1, 2019 via email

@fxdgear
Copy link
Author

fxdgear commented Jan 1, 2019 via email

@oma0256
Copy link

oma0256 commented Nov 4, 2019

@daneah @fxdgear I was this issue resolved?

@daneah
Copy link
Member

daneah commented Nov 5, 2019

@oma0256 I haven't been able to explore this any further since then. If you're able to provide details about your use case and the issue you're seeing (if anything differs from above), it would be helpful to me! I'm happy to try to get another release out soon if I can.

@daneah daneah closed this as completed Nov 5, 2019
@daneah daneah reopened this Nov 5, 2019
@oma0256
Copy link

oma0256 commented Nov 5, 2019

@daneah I actually wanted to explore options of raising a PR to fix this, if it is still an issue.

@daneah
Copy link
Member

daneah commented Nov 6, 2019

@oma0256 submissions definitely welcome! If you need any help or have questions, please let me know. Otherwise, I look forward to your pull request 😄

@philgyford
Copy link
Contributor

It's been a while, but I've just tried the app and found the same problem (python 3.8, Django 3.1).

Either decorating the dispatch method:

class PostDetailView(DateDetailView):

    @method_decorator(include_webmention_information)
    def dispatch(self, *args, **kwargs):
        return super().dispatch(*args, **kwargs)

or the class:

@method_decorator(include_webmention_information, name="dispatch")
class PostDetailView(DateDetailView):

I get:

  File "/Users/phil/Projects/personal/django-hines/hines/weblogs/urls.py", line 4, in <module>
    from . import feeds, views
  File "/Users/phil/Projects/personal/django-hines/hines/weblogs/views.py", line 122, in <module>
    class PostDetailView(TemplateSetMixin, DateDetailView):
  File "/Users/phil/Projects/personal/django-hines/hines/weblogs/views.py", line 145, in PostDetailView
    def dispatch(self, *args, **kwargs):
  File "/Users/phil/.local/share/virtualenvs/django-hines-jsiYO4hw/lib/python3.8/site-packages/django/utils/decorators.py", line 63, in _dec
    return _multi_decorate(decorator, obj)
  File "/Users/phil/.local/share/virtualenvs/django-hines-jsiYO4hw/lib/python3.8/site-packages/django/utils/decorators.py", line 47, in _multi_decorate
    _update_method_wrapper(_wrapper, dec)
  File "/Users/phil/.local/share/virtualenvs/django-hines-jsiYO4hw/lib/python3.8/site-packages/django/utils/decorators.py", line 17, in _update_method_wrapper
    def dummy(*args, **kwargs):
  File "/Users/phil/.local/share/virtualenvs/django-hines-jsiYO4hw/lib/python3.8/site-packages/django/utils/decorators.py", line 117, in _decorator
    middleware = middleware_class(view_func, *m_args, **m_kwargs)
TypeError: WebMentionMiddleware() takes no arguments

Googling, I guess WebMentionMiddleware() needs to be updated to include __init__() and __call__() methods as in the instructions? Looks like that was changed in Django 1.10.

@daneah
Copy link
Member

daneah commented Aug 22, 2020

@philgyford thanks for the details! An alternative for backward compatibility would be to use the MiddlewareMixin—hard to say how many are still using the old-style middleware.

I should be able to get to this today unless you're interested in taking a stab at it.

@philgyford
Copy link
Contributor

Sure - I'm stabbing at it right now :)

@daneah
Copy link
Member

daneah commented Aug 22, 2020

@philgyford oh, afraid I may have misled you! There already exist an old and a new version of the middleware—the problem being that the decorator uses the old one.

I could see adding a second decorator that uses the new middleware, but suggestions also welcome.

@philgyford
Copy link
Contributor

Ah, right. I'm not sure then. A second decorator maybe makes sense then? TBH I've never written decorators or middleware so anything beyond adding that mixin is probably going to take me a lot longer than someone with more experience, if you have time. Sorry!

@daneah
Copy link
Member

daneah commented Aug 22, 2020

No worries, I’ll have a look 😄

@daneah
Copy link
Member

daneah commented Aug 23, 2020

This should now be fixed in django-webmention==2.0.0

@philgyford
Copy link
Contributor

Great, many thanks @daneah!

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.

4 participants