Skip to content

Commit cadf22b

Browse files
wwwjfyfantix
authored andcommitted
fix python-gino/gino#407, extensions accept kwargs for db init
1 parent aba7cbb commit cadf22b

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

gino/ext/sanic.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ async def before_server_start(_, loop):
113113
max_size=app.config.setdefault('DB_POOL_MAX_SIZE', 10),
114114
ssl=app.config.setdefault('DB_SSL'),
115115
loop=loop,
116+
**app.config.setdefault('DB_KWARGS', dict()),
116117
)
117118

118119
@app.listener('after_server_stop')

tests/test_sanic.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,18 @@
88

99
from .models import DB_ARGS, PG_URL
1010

11+
_MAX_INACTIVE_CONNECTION_LIFETIME = 59.0
12+
1113

1214
# noinspection PyShadowingNames
1315
async def _app(config):
1416
app = sanic.Sanic()
1517
app.config.update(config)
18+
app.config.update({
19+
'DB_KWARGS': dict(
20+
max_inactive_connection_lifetime=_MAX_INACTIVE_CONNECTION_LIFETIME,
21+
),
22+
})
1623

1724
db = Gino(app)
1825

@@ -24,6 +31,10 @@ class User(db.Model):
2431

2532
@app.route('/')
2633
async def root(request):
34+
conn = await request['connection'].get_raw_connection()
35+
# noinspection PyProtectedMember
36+
assert conn._holder._max_inactive_time == \
37+
_MAX_INACTIVE_CONNECTION_LIFETIME
2738
return text('Hello, world!')
2839

2940
@app.route('/users/<uid:int>')

0 commit comments

Comments
 (0)