@@ -73,6 +73,11 @@ def _validate_settings(is_test, temp_db, preserved, conn_host):
73
73
'only when `TESTING` is set to true.'
74
74
raise InvalidSettingsError (msg )
75
75
76
+ def __get_app_config (key ):
77
+ return (_app_instance .get (key , False )
78
+ if isinstance (_app_instance , dict )
79
+ else _app_instance .config .get (key , False ))
80
+
76
81
def get_connection (alias = DEFAULT_CONNECTION_NAME , reconnect = False ):
77
82
global _connections
78
83
set_global_attributes ()
@@ -98,9 +103,9 @@ def get_connection(alias=DEFAULT_CONNECTION_NAME, reconnect=False):
98
103
conn_settings .pop ('password' , None )
99
104
conn_settings .pop ('authentication_source' , None )
100
105
101
- is_test = _app_instance . config . get ('TESTING' , False )
102
- temp_db = _app_instance . config . get ('TEMP_DB' , False )
103
- preserved = _app_instance . config . get ('PRESERVE_TEMP_DB' , False )
106
+ is_test = __get_app_config ('TESTING' )
107
+ temp_db = __get_app_config ('TEMP_DB' )
108
+ preserved = __get_app_config ('PRESERVE_TEMP_DB' )
104
109
105
110
# Validation
106
111
_validate_settings (is_test , temp_db , preserved , conn_host )
@@ -351,7 +356,7 @@ def create_connection(config, app):
351
356
@param app: instance of flask.Flask
352
357
"""
353
358
global _connection_settings , _app_instance
354
- _app_instance = app
359
+ _app_instance = app if app else config
355
360
356
361
if config is None or not isinstance (config , dict ):
357
362
raise Exception ("Invalid application configuration" );
@@ -363,6 +368,7 @@ def create_connection(config, app):
363
368
connections = {}
364
369
for conn_setting in conn_settings :
365
370
alias = conn_setting ['alias' ]
371
+ _connection_settings [alias ] = conn_setting
366
372
connections [alias ] = get_connection (alias )
367
373
return connections
368
374
else :
0 commit comments