Opened 14 years ago

Closed 11 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)

fix.diff (1.8 KB ) - added by Karataev Pavel 14 years ago.
test.diff (791 bytes ) - added by Karataev Pavel 14 years ago.

Download all attachments as: .zip

Change History (13)

by Karataev Pavel, 14 years ago

Attachment: fix.diff added

comment:1 by Russell Keith-Magee, 14 years ago

Has patch: set
Needs tests: set
Triage Stage: UnreviewedAccepted

I am prompted to ask "why?", but using wraps on is good practice in general, so I'll accept.

in reply to:  1 comment:2 by Karataev Pavel, 14 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 Karataev Pavel, 14 years ago

Attachment: test.diff added

comment:3 by Karataev Pavel, 14 years ago

Resolution: duplicate
Status: newclosed

duplicate to #11891

comment:4 by Carl Meyer, 14 years ago

Resolution: duplicate
Status: closedreopened

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 Luke Plant, 13 years ago

Type: Bug

comment:6 by Luke Plant, 13 years ago

Severity: Normal

comment:7 by Aymeric Augustin, 12 years ago

UI/UX: unset

Change UI/UX from NULL to False.

comment:8 by Aymeric Augustin, 12 years ago

Easy pickings: unset

Change Easy pickings from NULL to False.

comment:9 by caleb.smithnc@…, 12 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:10 by Caleb Smith <csmith@…>, 12 years ago

In 210fd7c658a44e51f4696555b3ce71498db55d96:

refs #12836 - Added a test to assure permalink wraps method attributes

comment:11 by Stephen Burrows, 11 years ago

Resolution: fixed
Status: reopenedclosed

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.

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