Opened 11 years ago

Closed 2 years ago

Last modified 2 years ago

#22078 closed Bug (fixed)

views.Feed methods cannot be decorated

Reported by: Germano Gabbianelli Owned by: Marcelo Galigniana
Component: contrib.syndication Version: 1.6
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes 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 11 years ago.
sample project, which show how patch works now

Download all attachments as: .zip

Change History (21)

comment:1 by Aymeric Augustin, 11 years ago

Triage Stage: UnreviewedAccepted

Yes, that code is fragile.

comment:2 by coldmin, 11 years ago

Owner: changed from nobody to coldmin
Status: newassigned

comment:3 by coldmin, 11 years ago

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

by coldmin, 11 years ago

Attachment: t22078.zip added

sample project, which show how patch works now

comment:4 by coldmin, 11 years ago

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 work now (sample project is in attachments)

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

comment:5 by Mariusz Felisiak, 3 years ago

Owner: coldmin removed
Status: assignednew

comment:6 by Marcelo Galigniana, 3 years ago

Owner: set to Marcelo Galigniana
Status: newassigned

comment:7 by Marcelo Galigniana, 3 years ago

Has patch: set

Pull Request created: PR

comment:8 by Mariusz Felisiak, 3 years ago

Patch needs improvement: set

comment:9 by Marcelo Galigniana, 3 years ago

Patch needs improvement: unset

comment:10 by Mariusz Felisiak, 2 years ago

Patch needs improvement: set

comment:11 by Mariusz Felisiak <felisiak.mariusz@…>, 2 years ago

In 241fe59b:

Refs #22078 -- Added syndication test for feeds with callable objects.

comment:12 by Mariusz Felisiak, 2 years ago

Needs tests: set

comment:13 by Marcelo Galigniana, 2 years ago

Needs tests: unset
Patch needs improvement: unset

comment:14 by Mariusz Felisiak, 2 years ago

Needs tests: set
Patch needs improvement: set

comment:15 by Marcelo Galigniana, 2 years ago

Needs tests: unset
Patch needs improvement: unset

comment:16 by Mariusz Felisiak <felisiak.mariusz@…>, 2 years ago

In 7e4656e4:

Refs #22078 -- Added syndication test for feeds with static methods.

comment:17 by Mariusz Felisiak, 2 years ago

Triage Stage: AcceptedReady for checkin

comment:18 by Mariusz Felisiak <felisiak.mariusz@…>, 2 years ago

In 9d3b8120:

[4.1.x] Refs #22078 -- Added syndication test for feeds with static methods.

Backport of 7e4656e4b2189390a433a149091442d53a777e2b from main.

comment:19 by Mariusz Felisiak <felisiak.mariusz@…>, 2 years ago

Resolution: fixed
Status: assignedclosed

In 8c0886b0:

Fixed #22078 -- Fixed crash of Feed with decorated methods.

comment:20 by Mariusz Felisiak <felisiak.mariusz@…>, 2 years ago

In 0210dbcb:

[4.1.x] Fixed #22078 -- Fixed crash of Feed with decorated methods.

Backport of 8c0886b068ba4e224dd78104b93c9638b860b398 from main.

Note: See TracTickets for help on using tickets.
Back to Top