Opened 14 months ago

Last modified 12 months ago

#22078 assigned Bug

views.Feed methods cannot be decorated

Reported by: tyrion Owned by: coldmind
Component: contrib.syndication Version: 1.6
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

If one applies a decorator on a method which is called by __get_dynamic_attr a TypeError like this occurs:

Exception Type: TypeError at /blog/feed/
Exception Value: item_link() takes exactly 2 arguments (1 given)

I think this is because __get_dynamic_attr tries to count the function's arguments, but decorators usally get defined with the *args, **kwargs syntax, so this trick does not work here.

            if code.co_argcount == 2:       # one argument is 'self'
                return attr(obj)
            else:
                return attr()

I think the best approach would be to remove one of the two methods. IMHO We should have either attr(item) or attr() not both, as "there should be one, and preferably only one, obvious way to do it".

Attachments (1)

t22078.zip (13.5 KB) - added by coldmin 12 months ago.
sample project, which show how patch works now

Download all attachments as: .zip

Change History (6)

comment:1 Changed 13 months ago by aaugustin

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

Yes, that code is fragile.

comment:2 Changed 12 months ago by coldmin

  • Owner changed from nobody to coldmin
  • Status changed from new to assigned

comment:3 Changed 12 months ago by coldmin

I reproduced it. I'm working now on fix.

Changed 12 months ago by coldmin

sample project, which show how patch works now

comment:4 Changed 12 months ago by coldmin

I sended pull request.
https://github.com/django/django/pull/2584

The problem is that methods without the 'item' argument (only with self) should be static now:

    @staticmethod
    def item_description(self):
        return force_text(item)

But the decorators works now (sample project is in attachments)

Last edited 12 months ago by coldmin (previous) (diff)

comment:5 Changed 12 months ago by coldmind

  • Owner changed from coldmin to coldmind
Note: See TracTickets for help on using tickets.
Back to Top