Code

Opened 4 years ago

Closed 19 months ago

#12836 closed Bug (fixed)

Model.get_absolute_url lose method attributes

Reported by: minmax Owned by: minmax
Component: Database layer (models, ORM) Version: master
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 minmax 4 years ago.
test.diff (791 bytes) - added by minmax 4 years ago.

Download all attachments as: .zip

Change History (13)

Changed 4 years ago by minmax

comment:1 follow-up: Changed 4 years ago by russellm

  • Has patch set
  • Needs documentation unset
  • Needs tests set
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

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

comment:2 in reply to: ↑ 1 Changed 4 years ago by minmax

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

Changed 4 years ago by minmax

comment:3 Changed 4 years ago by minmax

  • Resolution set to duplicate
  • Status changed from new to closed

duplicate to #11891

comment:4 Changed 4 years ago by carljm

  • Resolution duplicate deleted
  • Status changed from closed to 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 Changed 3 years ago by lukeplant

  • Type set to Bug

comment:6 Changed 3 years ago by lukeplant

  • Severity set to Normal

comment:7 Changed 2 years ago by aaugustin

  • UI/UX unset

Change UI/UX from NULL to False.

comment:8 Changed 2 years ago by aaugustin

  • Easy pickings unset

Change Easy pickings from NULL to False.

comment:9 Changed 20 months ago by caleb.smithnc@…

  • 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 Changed 19 months ago by Caleb Smith <csmith@…>

In 210fd7c658a44e51f4696555b3ce71498db55d96:

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

comment:11 Changed 19 months ago by melinath

  • Resolution set to fixed
  • Status changed from reopened to 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.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.