Opened 6 years ago

Last modified 3 years ago

#22078 assigned Bug

views.Feed methods cannot be decorated

Reported by: Germano Gabbianelli Owned by: Andriy Sokolovskiy
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 6 years ago.
sample project, which show how patch works now

Download all attachments as: .zip

Change History (6)

comment:1 Changed 6 years ago by Aymeric Augustin

Triage Stage: UnreviewedAccepted

Yes, that code is fragile.

comment:2 Changed 6 years ago by coldmin

Owner: changed from nobody to coldmin
Status: newassigned

comment:3 Changed 6 years ago by coldmin

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

Changed 6 years ago by coldmin

Attachment: added

sample project, which show how patch works now

comment:4 Changed 6 years 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 work now (sample project is in attachments)

Last edited 3 years ago by Anton Samarchyan (previous) (diff)

comment:5 Changed 6 years ago by Andriy Sokolovskiy

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