Skip to content

Commit 3bc8495

Browse files
author
David McLean
committed
default db-engine to master if context is missing
Currently if the db is invoked without app_context flask_replicated fails with a RunTimeError. Instead default to the master if app_context is missing.
1 parent 6bbbc1b commit 3bc8495

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

flask_replicated.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def init_app(self, app):
2222
get_engine_vanilla = db.get_engine
2323

2424
def get_replicated_engine(app=app, bind=None):
25-
if bind is None:
25+
if bind is None and g:
2626
use_slave = getattr(g, 'use_slave', False)
2727
use_master = getattr(g, 'use_master', False)
2828
if use_slave and not use_master:
@@ -42,6 +42,7 @@ def changes_database(func):
4242
func.use_master_database = True
4343
return func
4444

45+
4546
def use_slave_database(func):
4647
func.use_slave_database = True
4748
return func

0 commit comments

Comments
 (0)