|
19 | 19 | _tmpdir = None |
20 | 20 | _conn = None |
21 | 21 | _process = None |
| 22 | +_app_instance = current_app |
22 | 23 |
|
23 | 24 | class InvalidSettingsError(Exception): |
24 | 25 | pass |
@@ -97,9 +98,9 @@ def get_connection(alias=DEFAULT_CONNECTION_NAME, reconnect=False): |
97 | 98 | conn_settings.pop('password', None) |
98 | 99 | conn_settings.pop('authentication_source', None) |
99 | 100 |
|
100 | | - is_test = current_app.config.get('TESTING', False) |
101 | | - temp_db = current_app.config.get('TEMP_DB', False) |
102 | | - preserved = current_app.config.get('PRESERVE_TEMP_DB', False) |
| 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) |
103 | 104 |
|
104 | 105 | # Validation |
105 | 106 | _validate_settings(is_test, temp_db, preserved, conn_host) |
@@ -313,7 +314,7 @@ def fetch_connection_settings(config, removePass=True): |
313 | 314 | # Connection settings provided in standard format. |
314 | 315 | return _resolve_settings(config, removePass) |
315 | 316 |
|
316 | | -def create_connection(config): |
| 317 | +def create_connection(config, app): |
317 | 318 | """ |
318 | 319 | Connection is created based on application configuration |
319 | 320 | setting. Application settings which is enabled as TESTING |
@@ -346,9 +347,10 @@ def create_connection(config): |
346 | 347 | >> app.config['TEMP_DB_LOC'] = '/path/to/temp_dir/' |
347 | 348 |
|
348 | 349 | @param config: Flask-MongoEngine application configuration. |
349 | | -
|
| 350 | + @param app: instance of flask.Flask |
350 | 351 | """ |
351 | | - global _connection_settings |
| 352 | + global _connection_settings, _app_instance |
| 353 | + _app_instance = app |
352 | 354 |
|
353 | 355 | if config is None or not isinstance(config, dict): |
354 | 356 | raise Exception("Invalid application configuration"); |
|
0 commit comments