Opened 16 years ago
Closed 13 years ago
#12836 closed Bug (fixed)
Model.get_absolute_url lose method attributes
| Reported by: | Karataev Pavel | Owned by: | Karataev Pavel |
|---|---|---|---|
| Component: | Database layer (models, ORM) | Version: | dev |
| Severity: | Normal | Keywords: | |
| Cc: | Triage Stage: | Accepted | |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
class MyModel(models.Mode):
@models.permalink
@set_attr('x', 10) # set some attribute to MyModel.get_absolute_url method
def get_absolute_url(self):
return ('some', (self.attr, ))
>>>print MyModel().get_absolute_url.x
AttributeError: 'function' object has no attribute 'x'
Attachments (2)
Change History (13)
by , 16 years ago
follow-up: 2 comment:1 by , 16 years ago
| Has patch: | set |
|---|---|
| Needs tests: | set |
| Triage Stage: | Unreviewed → Accepted |
comment:2 by , 16 years ago
Replying to russellm:
I am prompted to ask "why?", but using wraps on is good practice in general, so I'll accept.
i am use my own cache decorator on get_absolute_url, and it store some object in function
by , 16 years ago
comment:4 by , 16 years ago
| Resolution: | duplicate |
|---|---|
| Status: | closed → reopened |
This is not actually a duplicate of #11891. That ticket is about replacement of get_absolute_url in ModelBase, this one is about @models.permalink.
comment:5 by , 15 years ago
| Type: | → Bug |
|---|
comment:6 by , 15 years ago
| Severity: | → Normal |
|---|
comment:9 by , 13 years ago
| Needs tests: | unset |
|---|
I added a pull request that adds the test here: https://github.com/django/django/pull/360
The fix.diff at the top was already applied, but the doc test in test.diff isn't. I simply rewrote it as a unit test.
comment:11 by , 13 years ago
| Resolution: | → fixed |
|---|---|
| Status: | reopened → closed |
So apparently this was fixed as a side effect of fixing #15604. (See https://github.com/django/django/commit/72c57338). And the commit referenced by Caleb above adds tests for the specific use case mentioned here.
I am prompted to ask "why?", but using wraps on is good practice in general, so I'll accept.