Opened 19 months ago

Last modified 17 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


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)
                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) (13.5 KB) - added by coldmin 17 months ago.
sample project, which show how patch works now

Download all attachments as: .zip

Change History (6)

comment:1 Changed 18 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 17 months ago by coldmin

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

comment:3 Changed 17 months ago by coldmin

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

Changed 17 months ago by coldmin

sample project, which show how patch works now

comment:4 Changed 17 months ago by coldmin

I sended pull request.

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

    def item_description(self):
        return force_text(item)

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

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

comment:5 Changed 17 months ago by coldmind

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