Black Lives Matter. Please consider donating to Black Girls Code today.
Dash HoloViews is now available! Check out the docs.

Flask_Sqlalchemy querying with dash callbacks

I’m trying to query data based upon callbacks from dash in a multi page app (main motive - to get most recent data based on date. otherwise i have to use a global variable which is loaded only when the server restarts).
But I get an error when this query is executed only from the callback function. This does not occur when the query is executed from global variable definition.

Please find the error below:

Traceback (most recent call last):
File “C:\Program Files\Python36\lib\site-packages\flask\app.py”, line 2309, in
call
return self.wsgi_app(environ, start_response)
File “C:\Program Files\Python36\lib\site-packages\flask\app.py”, line 2295, in
wsgi_app
response = self.handle_exception(e)
File “C:\Program Files\Python36\lib\site-packages\flask\app.py”, line 1741, in
handle_exception
reraise(exc_type, exc_value, tb)
File “C:\Program Files\Python36\lib\site-packages\flask_compat.py”, line 35,
in reraise
raise value
File “C:\Program Files\Python36\lib\site-packages\flask\app.py”, line 2292, in
wsgi_app
response = self.full_dispatch_request()
File “C:\Program Files\Python36\lib\site-packages\flask\app.py”, line 1815, in
full_dispatch_request
rv = self.handle_user_exception(e)
File “C:\Program Files\Python36\lib\site-packages\flask\app.py”, line 1718, in
handle_user_exception
reraise(exc_type, exc_value, tb)
File “C:\Program Files\Python36\lib\site-packages\flask_compat.py”, line 35,
in reraise
raise value
File “C:\Program Files\Python36\lib\site-packages\flask\app.py”, line 1813, in
full_dispatch_request
rv = self.dispatch_request()
File “C:\Program Files\Python36\lib\site-packages\flask\app.py”, line 1799, in
dispatch_request
return self.view_functionsrule.endpoint
File “C:\Program Files\Python36\lib\site-packages\dash\dash.py”, line 868, in
dispatch
return self.callback_map[target_id]‘callback’
File “C:\Program Files\Python36\lib\site-packages\dash\dash.py”, line 808, in
add_context
output_value = func(args, kwargs)
File “C:\projects\production\faptools-reporting-new\gtest\gtest.py”, line 150,
** in render_content

** layer_dict = get_data.get_layer_info(get_data.get_date_based_data(get_curren
*
t_date())[0], tab)
** File “C:\projects\production\faptools-reporting-new\gtest\gtest.py”, line 21,**
in get_current_date
** output = gtest_db.query.order_by(gtest_db.result_date.desc()).limit(1).all()**

File "C:\Program Files\Python36\lib\site-packages\flask_sqlalchemy_init_.py
", line 514, in get
return type.query_class(mapper, session=self.sa.session())
File “C:\Program Files\Python36\lib\site-packages\sqlalchemy-1.2.11-py3.6-win-
amd64.egg\sqlalchemy\orm\scoping.py”, line 74, in call
return self.registry()
File “C:\Program Files\Python36\lib\site-packages\sqlalchemy-1.2.11-py3.6-win-
amd64.egg\sqlalchemy\util_collections.py”, line 1001, in call
return self.registry.setdefault(key, self.createfunc())
File “C:\Program Files\Python36\lib\site-packages\sqlalchemy-1.2.11-py3.6-win-
amd64.egg\sqlalchemy\orm\session.py”, line 2950, in call
return self.class_(**local_kw)
File "C:\Program Files\Python36\lib\site-packages\flask_sqlalchemy_init_.py
", line 142, in init
track_modifications = app.config[‘SQLALCHEMY_TRACK_MODIFICATIONS’]
KeyError: ‘SQLALCHEMY_TRACK_MODIFICATIONS’

What was the solution?