]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Prevent loading contextvars in python 3.6
authorFederico Caselli <cfederico87@gmail.com>
Thu, 1 Apr 2021 18:33:53 +0000 (20:33 +0200)
committerFederico Caselli <cfederico87@gmail.com>
Thu, 1 Apr 2021 18:34:39 +0000 (20:34 +0200)
Fixes: #6166
Change-Id: I1355e9a8b6455ca377892214e9426c8f70441f98

doc/build/changelog/unreleased_14/6166.rst [new file with mode: 0644]
lib/sqlalchemy/util/_concurrency_py3k.py

diff --git a/doc/build/changelog/unreleased_14/6166.rst b/doc/build/changelog/unreleased_14/6166.rst
new file mode 100644 (file)
index 0000000..5070304
--- /dev/null
@@ -0,0 +1,6 @@
+.. change::
+    :tags: bug, asyncio
+    :tickets: 6166
+
+    Prevent loading contextvars in python 3.6 when the backport
+    library is installed.
index 94f4705d88307dea6133c4e89fced2878da5034a..b905f903b83fec6199db8ab84db7e27ae589a3ac 100644 (file)
@@ -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