Opened 12 years ago

Closed 12 years ago

Last modified 12 years ago

#3009 closed enhancement (wontfix)

Add a decorator for alters_data

Reported by: gulopine@… Owned by: Adrian Holovaty
Component: Tools Version:
Severity: normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


It seems reasonable to me that functions which alter data should be able to use a decorator to denote that, rather than needing to set alters_data = True on a separate line after the function declaration. The following function, avaialble somewhere within Django, could be imported and used as a decorator to enable the alters_data functionality in a more understandable manner.

def alters_data(func):
    func.alters_data = True
    return func

Change History (7)

comment:1 Changed 12 years ago by gulopine@…

Type: defectenhancement

comment:2 Changed 12 years ago by Adrian Holovaty

Resolution: wontfix
Status: newclosed

Ehh, this isn't worth it. If people are too lazy to do it by setting a function attribute, they can include this decorator in their own code.

comment:3 Changed 12 years ago by Orestis Markou <orestis@…>

Resolution: wontfix
Status: closedreopened

Adrian: Why force people to do that ? There already are decorators the define attitude, like requires_login, user_passes_test, transaction.commit_on_success etc.

Providing this out of the box (as well as other decorators) provides a consistent experience on describing view function behavior.

comment:4 Changed 12 years ago by Adrian Holovaty

Resolution: wontfix
Status: reopenedclosed

Orestis: Those other decorators you mention all do complex things, whereas the alters_data decorator suggested in this ticket only does a simple thing that's already easy enough to do a different way.

comment:5 Changed 12 years ago by James Bennett

(stepping in after watching this one for a day or so)

I guess I'm kinda confused about what the efficiency gain is; regardless of which way it's done it's a single line of code to apply alters_data to a function; the only difference is that right now there's one way to do it (func.alters_data = True) while introducing a decorator would bump that to three (the original, plus each of the 2.3 and 2.4 decorator syntaxes).

What's the perceived gain from this?

comment:6 Changed 12 years ago by gulopine@…

Thank you for your prompt responses on this matter, and for giving it appropriate consideration.

comment:7 Changed 12 years ago by Orestis Markou <orestis@…>

Oops my bad. alter_data isn't defined in a view function, it's defined in a model/object function. So yes, creating a decorator for it seems unnecessary.

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