#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)
Change History (21)
comment:1 by , 11 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:2 by , 11 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:4 by , 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)
comment:5 by , 3 years ago
Owner: | removed |
---|---|
Status: | assigned → new |
comment:6 by , 3 years ago
Owner: | set to |
---|---|
Status: | new → assigned |
comment:8 by , 3 years ago
Patch needs improvement: | set |
---|
comment:9 by , 3 years ago
Patch needs improvement: | unset |
---|
comment:10 by , 3 years ago
Patch needs improvement: | set |
---|
comment:12 by , 3 years ago
Needs tests: | set |
---|
comment:13 by , 3 years ago
Needs tests: | unset |
---|---|
Patch needs improvement: | unset |
comment:14 by , 3 years ago
Needs tests: | set |
---|---|
Patch needs improvement: | set |
comment:15 by , 3 years ago
Needs tests: | unset |
---|---|
Patch needs improvement: | unset |
comment:17 by , 3 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
Yes, that code is fragile.