Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove run_on_exit decorator param #27

Open
hugorodgerbrown opened this issue Nov 6, 2022 · 0 comments
Open

Remove run_on_exit decorator param #27

hugorodgerbrown opened this issue Nov 6, 2022 · 0 comments
Assignees

Comments

@hugorodgerbrown
Copy link
Member

This is really only relevant for HttpResponse return values, and wrapping a view function with the decorator is no longer recommended. Extract logic into a separate function and wrap that instead.

BEFORE

# only process side-effects if the HttpResponse is 200 - ignore 404
@has_side_effects("foo", run_on_exit: lambda r: r.status_code=200)
def view_func(request: HttpRequest) -> HttpResponse:
    obj = get_obj_or_404()
    obj.foo()
    return HttpResponse("ok")

AFTER

def view_func(request: HttpRequest) -> HttpResponse:
    obj = get_obj_or_404()
    do_something_with_obj(obj)
    return HttpResponse("ok")

@has_side_effects("foo")
def do_something_with_obj(obj) -> None:
    obj.foo()
@hugorodgerbrown hugorodgerbrown self-assigned this Dec 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant