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

Error running query: Working outside of application context #3662

Closed
gobird-yh opened this issue Apr 1, 2019 · 3 comments
Closed

Error running query: Working outside of application context #3662

gobird-yh opened this issue Apr 1, 2019 · 3 comments

Comments

@gobird-yh
Copy link

hi, all
i get a problem.
env: win10 64bit
version: redash7.0.0(dev)
python: python2.7.15
IDE: pycharm2019.1 X64

npm: run watch
celery:celery worker --app=redash.worker --pool=eventlet -Qscheduled_queries,queries,celery -c2
flask:FLASK_APP = redash.wsgi
FLASK_ENV = development
FLASK_DEBUG = 1
python -m flask run

redash is running like ok. http://localhost:5000 can work;
but when use queries,excute error

Error running query: Working outside of application context. This typically means that you attempted to use functionality that needed to interface with the current application object in a way. To solve this set up an application context with app.app_context(). See the documentation for more information.

i think the worker.py run not good.


    def __call__(self, *args, **kwargs):
        with current_app.app_context():
            return TaskBase.__call__(self, *args, **kwargs)


@worker_process_init.connect
def init_celery_flask_app(**kwargs):
    app = create_app()
    app.app_context().push()

the error information notice the app.app_context(),i cannot solve it.
can anyone solute the problem?

@ranbena
Copy link
Contributor

ranbena commented Apr 1, 2019

Hey @gobird-yh, as noted in the github issue template, we use GitHub only for bug reports
but for support questions plz use https://discuss.redash.io/c/support, so go ahead and copy this over to there.

@ranbena ranbena closed this as completed Apr 1, 2019
@xiongyingeng
Copy link

Hey @gobird-yh, you can try this.

def __call__(self, *args, **kwargs):
    from redash.wsgi import app
    with app.app_context():
        return TaskBase.__call__(self, *args, **kwargs)

@arikfr
Copy link
Member

arikfr commented May 1, 2019

If someone happens to have this again, can you please search your logs (before the Out of Context error message) for something like:

Signal handler <function init_celery_flask_app at 0x7f0b6c2f4c08> raised:

I think the issue is caused when init_celery_flask_app raises an error. Looks like Celery will continue the boot process anyway, but in this case there will be no app context available.

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

4 participants