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

after_this_request fails with a meaningless error when used outside request context #4333

Closed
ThiefMaster opened this issue Nov 10, 2021 · 2 comments

Comments

@ThiefMaster
Copy link
Member

@ThiefMaster ThiefMaster commented Nov 10, 2021

_request_ctx_stack.top._after_request_functions.append(f)

While it makes no sense to use it outside a context, the error message could be nicer when you do so anyway (e.g. because you accidentally call a function using it from a celery task or some other place without a request context), like e.g. in copy_current_request_context in the same file.

AttributeError: 'NoneType' object has no attribute '_after_request_functions'
  ...
  File "flask/ctx.py", line 133, in after_this_request
    _request_ctx_stack.top._after_request_functions.append(f)
@afzal442
Copy link

@afzal442 afzal442 commented Nov 16, 2021

hi @ThiefMaster, I'd like to contribute here. Do you mean to add an error message that you shared above in copy_current_request_context in the function after_this_request itself ?

def after_this_request(f: AfterRequestCallable) -> AfterRequestCallable:
Thanks.

@darshang99
Copy link

@darshang99 darshang99 commented Dec 21, 2021

hey, is this still open I'm a beginner I would like to work on it.

@davidism davidism added this to the 2.0.3 milestone Dec 23, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 7, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants