From: Federico Caselli Date: Thu, 1 Apr 2021 18:33:53 +0000 (+0200) Subject: Prevent loading contextvars in python 3.6 X-Git-Tag: rel_1_4_5~7^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=508aee203d9ad6beb7bdb83a41b08deae6df0146;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Prevent loading contextvars in python 3.6 Fixes: #6166 Change-Id: I1355e9a8b6455ca377892214e9426c8f70441f98 --- diff --git a/doc/build/changelog/unreleased_14/6166.rst b/doc/build/changelog/unreleased_14/6166.rst new file mode 100644 index 0000000000..5070304956 --- /dev/null +++ b/doc/build/changelog/unreleased_14/6166.rst @@ -0,0 +1,6 @@ +.. change:: + :tags: bug, asyncio + :tickets: 6166 + + Prevent loading contextvars in python 3.6 when the backport + library is installed. diff --git a/lib/sqlalchemy/util/_concurrency_py3k.py b/lib/sqlalchemy/util/_concurrency_py3k.py index 94f4705d88..b905f903b8 100644 --- a/lib/sqlalchemy/util/_concurrency_py3k.py +++ b/lib/sqlalchemy/util/_concurrency_py3k.py @@ -6,16 +6,21 @@ from typing import Coroutine import greenlet +from . import compat from .. import exc -try: - from contextvars import copy_context as _copy_context - # If greenlet.gr_context is present in current version of greenlet, - # it will be set with a copy of the current context on creation. - # Refs: https://github.com/python-greenlet/greenlet/pull/198 - getattr(greenlet.greenlet, "gr_context") -except (ImportError, AttributeError): +if compat.py37: + try: + from contextvars import copy_context as _copy_context + + # If greenlet.gr_context is present in current version of greenlet, + # it will be set with a copy of the current context on creation. + # Refs: https://github.com/python-greenlet/greenlet/pull/198 + getattr(greenlet.greenlet, "gr_context") + except (ImportError, AttributeError): + _copy_context = None +else: _copy_context = None