Code

Opened 5 years ago

Closed 4 years ago

Last modified 3 years ago

#11891 closed (fixed)

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

Reported by: nfg 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: UI/UX:

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 nfg 5 years ago.
Preserve attributes of the original get_absolute_url method

Download all attachments as: .zip

Change History (10)

Changed 5 years ago by nfg

Preserve attributes of the original get_absolute_url method

comment:1 Changed 4 years ago by jacob

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

comment:2 Changed 4 years ago by russellm

  • Triage Stage changed from Accepted to Ready for checkin

comment:3 Changed 4 years ago by russellm

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

(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 Changed 4 years ago by russellm

(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 Changed 4 years ago by minmax

  • Resolution fixed deleted
  • Status changed from closed to reopened

need to fix models.permalink decorator

and #12836 market as duplicate

comment:6 Changed 4 years ago by ubernostrum

  • Resolution set to fixed
  • Status changed from reopened to closed

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 Changed 4 years ago by minmax

  • Resolution fixed deleted
  • Status changed from closed to reopened

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 Changed 4 years ago by carljm

  • Resolution set to fixed
  • Status changed from reopened to closed

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 Changed 3 years ago by jacob

  • milestone 1.2 deleted

Milestone 1.2 deleted

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.