Opened 15 years ago

Closed 15 years ago

Last modified 13 years ago

#11891 closed (fixed)

The attributes of the original get_absolute_url defined in the model is not copied

Reported by: Nils Fredrik Gjerull Owned by: nobody
Component: Database layer (models, ORM) Version: 1.1
Severity: Keywords: attributes get_absolute_url
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

I have made an app that assist in purging upstream web caches and it uses, among other methods, get_absolute_url. Because I don't always want to purge based on get_absolute_url I added an attribute to get_absolute_url named purge. This attribute gets lost because get_absolute_url is changed with the get_absolute_url that do absolute url overrides, curried with the original function. The original function's attributes should be added to the new curried function.

class AModel(models.Model):
    def get_absolute_url(self):
        return '/some_url/'
    get_absolute_url.purge = True

Attachments (1)

get_absolute_url_attributes.diff (2.7 KB ) - added by Nils Fredrik Gjerull 15 years ago.
Preserve attributes of the original get_absolute_url method

Download all attachments as: .zip

Change History (10)

by Nils Fredrik Gjerull, 15 years ago

Preserve attributes of the original get_absolute_url method

comment:1 by Jacob, 15 years ago

milestone: 1.2
Triage Stage: UnreviewedAccepted

comment:2 by Russell Keith-Magee, 15 years ago

Triage Stage: AcceptedReady for checkin

comment:3 by Russell Keith-Magee, 15 years ago

Resolution: fixed
Status: newclosed

(In [12766]) Fixed #11891 -- Ensured that attributes of get_absolute_url are preserved through the metaclass. Thanks to nfg for the report and patch.

comment:4 by Russell Keith-Magee, 15 years ago

(In [12767]) [1.1.X] Fixed #11891 -- Ensured that attributes of get_absolute_url are preserved through the metaclass. Thanks to nfg for the report and patch.

Backport of r12766 from trunk.

comment:5 by Karataev Pavel, 15 years ago

Resolution: fixed
Status: closedreopened

need to fix models.permalink decorator

and #12836 market as duplicate

comment:6 by James Bennett, 15 years ago

Resolution: fixed
Status: reopenedclosed

The fix in [12766] included unit tests to check that this works, and the tests pass; without proof that the fix didn't actually work, this shouldn't be reopened.

comment:7 by Karataev Pavel, 15 years ago

Resolution: fixed
Status: closedreopened

copy & paste from #12836

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'

comment:8 by Carl Meyer, 15 years ago

Resolution: fixed
Status: reopenedclosed

The problem here is that #12836 shouldn't have been closed as dupe in the first place. This ticket is about problems with the replacement of get_absolute_url in ModelBase, which is now fixed. #12836 is about @models.permalink not updating wrappers, which is a valid, but separate issue. Re-closing this as fixed, reopening #12836.

comment:9 by Jacob, 13 years ago

milestone: 1.2

Milestone 1.2 deleted

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