From 52c51dbf77056e8e10a3fa7337be0abd7271e850 Mon Sep 17 00:00:00 2001 From: pyup-bot Date: Sun, 9 Sep 2018 15:14:36 +0800 Subject: [PATCH 1/2] Update aiocontextvars from 0.1.2 to 0.2.0 --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 4be5082c..f0f2cae1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,3 @@ asyncpg==0.17.0 SQLAlchemy==1.2.11 -aiocontextvars==0.1.2;python_version<"3.7" +aiocontextvars==0.2.0;python_version<"3.7" From 07a11b049733f90521a1df9fdb8c18f3c7440836 Mon Sep 17 00:00:00 2001 From: Fantix King Date: Mon, 10 Sep 2018 09:58:33 +0800 Subject: [PATCH 2/2] Remove enable_inherit and disable_inherit, always use aiocontextvars==0.2.0 --- gino/engine.py | 9 +-------- gino/ext/aiohttp.py | 14 -------------- gino/ext/quart.py | 8 -------- gino/ext/sanic.py | 14 -------------- gino/ext/tornado.py | 7 ------- requirements.txt | 2 +- 6 files changed, 2 insertions(+), 52 deletions(-) diff --git a/gino/engine.py b/gino/engine.py index 1b0a11dc..8848cd46 100644 --- a/gino/engine.py +++ b/gino/engine.py @@ -4,20 +4,13 @@ import sys import time +from aiocontextvars import ContextVar from sqlalchemy.engine import Engine, Connection from sqlalchemy.sql import schema from .transaction import GinoTransaction -if sys.version_info >= (3, 7): - # noinspection PyPackageRequirements,PyUnresolvedReferences - from contextvars import ContextVar -else: - # noinspection PyPackageRequirements - from aiocontextvars import ContextVar # pragma: no cover - - class _BaseDBAPIConnection: _reset_agent = None gino_conn = None diff --git a/gino/ext/aiohttp.py b/gino/ext/aiohttp.py index e7b1a4c5..9ec34b08 100644 --- a/gino/ext/aiohttp.py +++ b/gino/ext/aiohttp.py @@ -1,11 +1,6 @@ # noinspection PyPackageRequirements from aiohttp.web import HTTPNotFound, middleware from sqlalchemy.engine.url import URL -try: - # noinspection PyPackageRequirements - from aiocontextvars import enable_inherit, disable_inherit -except ImportError: - enable_inherit = disable_inherit = lambda loop: None from ..api import Gino as _Gino, GinoExecutor as _Executor from ..engine import GinoConnection as _Connection, GinoEngine as _Engine @@ -114,15 +109,9 @@ async def _middleware(self, request, handler): def init_app(self, app): app['db'] = self - inherit_enabled = [False] - config = app['config'].get('gino', {}) async def before_server_start(app_): - if config.setdefault('enable_inherit', True): - enable_inherit(app_.loop) - inherit_enabled[0] = True - if config.get('dsn'): dsn = config['dsn'] else: @@ -145,9 +134,6 @@ async def before_server_start(app_): async def after_server_stop(app_): await self.pop_bind().close() - if inherit_enabled[0]: - disable_inherit(app_.loop) - inherit_enabled[0] = False app.on_startup.append(before_server_start) app.on_cleanup.append(after_server_stop) diff --git a/gino/ext/quart.py b/gino/ext/quart.py index f849d653..54a817ea 100644 --- a/gino/ext/quart.py +++ b/gino/ext/quart.py @@ -5,11 +5,6 @@ # noinspection PyPackageRequirements from quart.exceptions import NotFound from sqlalchemy.engine.url import URL -try: - # noinspection PyPackageRequirements - from aiocontextvars import enable_inherit, disable_inherit -except ImportError: - enable_inherit = disable_inherit = lambda loop: None from ..api import Gino as _Gino, GinoExecutor as _Executor from ..engine import GinoConnection as _Connection, GinoEngine as _Engine @@ -108,9 +103,6 @@ async def after_response(response): @app.before_first_request async def before_first_request(): - if app.config.setdefault('DB_USE_CONNECTION_FOR_REQUEST', True): - enable_inherit(asyncio.get_event_loop()) - dsn = app.config.get('DB_DSN') if not dsn: dsn = URL( diff --git a/gino/ext/sanic.py b/gino/ext/sanic.py index 1d7b34dd..0675351c 100644 --- a/gino/ext/sanic.py +++ b/gino/ext/sanic.py @@ -1,11 +1,6 @@ # noinspection PyPackageRequirements from sanic.exceptions import NotFound from sqlalchemy.engine.url import URL -try: - # noinspection PyPackageRequirements - from aiocontextvars import enable_inherit, disable_inherit -except ImportError: - enable_inherit = disable_inherit = lambda loop: None from ..api import Gino as _Gino, GinoExecutor as _Executor from ..engine import GinoConnection as _Connection, GinoEngine as _Engine @@ -86,8 +81,6 @@ def __init__(self, app=None, *args, **kwargs): self.init_app(app) def init_app(self, app): - inherit_enabled = [False] - if app.config.setdefault('DB_USE_CONNECTION_FOR_REQUEST', True): @app.middleware('request') async def on_request(request): @@ -101,10 +94,6 @@ async def on_response(request, _): @app.listener('before_server_start') async def before_server_start(_, loop): - if app.config.setdefault('DB_USE_CONNECTION_FOR_REQUEST', True): - enable_inherit(loop) - inherit_enabled[0] = True - if app.config.get('DB_DSN'): dsn = app.config.DB_DSN else: @@ -128,9 +117,6 @@ async def before_server_start(_, loop): @app.listener('after_server_stop') async def after_server_stop(_, loop): await self.pop_bind().close() - if inherit_enabled[0]: - disable_inherit(loop) - inherit_enabled[0] = False async def first_or_404(self, *args, **kwargs): rv = await self.first(*args, **kwargs) diff --git a/gino/ext/tornado.py b/gino/ext/tornado.py index d1b8066c..13ca4f74 100644 --- a/gino/ext/tornado.py +++ b/gino/ext/tornado.py @@ -164,11 +164,6 @@ async def get(self, uid): from sqlalchemy.engine.url import URL from tornado.options import options as _options, define as _define -try: - # noinspection PyPackageRequirements - from aiocontextvars import enable_inherit as _enable_inherit -except ImportError: - _enable_inherit = lambda _: None # NOQA from ..api import Gino as _Gino, GinoExecutor as _Executor from ..engine import GinoConnection as _Connection, GinoEngine as _Engine @@ -325,8 +320,6 @@ async def late_init(self, db: Gino, *, loop=None, options=_options): else: raise RuntimeError('AsyncIOLoop is required to run GINO') - _enable_inherit(asyncio_loop) - self.db = db if 'dsn' in options: diff --git a/requirements.txt b/requirements.txt index f0f2cae1..33eefc3c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,3 @@ asyncpg==0.17.0 SQLAlchemy==1.2.11 -aiocontextvars==0.2.0;python_version<"3.7" +aiocontextvars==0.2.0