]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
adjust log stacklevel for py3.11.0b1; enable greenlet
authorMike Bayer <mike_mp@zzzcomputing.com>
Sat, 14 May 2022 14:25:53 +0000 (10:25 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 15 May 2022 14:31:51 +0000 (10:31 -0400)
Fixed issue where support for logging "stacklevel" implemented in
:ticket:`7612` required adjustment to work with recently released Python
3.11.0b1, also repairs the unit tests which tested this feature.

Install greenlet from a py311 compat patch.

re: the stacklevel thing, this is going to be very inconvenient
if we have to keep hardcoding numbers everywhere for every
new python version

Change-Id: I0c8f7293e98c0ca5cc544538284bfd1d3020cb1f
References: https://github.com/python-greenlet/greenlet/issues/288
Fixes: #8019
doc/build/changelog/unreleased_14/8019.rst [new file with mode: 0644]
lib/sqlalchemy/engine/base.py
lib/sqlalchemy/log.py
lib/sqlalchemy/testing/requirements.py
lib/sqlalchemy/util/__init__.py
test/ext/asyncio/test_engine_py3k.py
test/requirements.py
tox.ini

diff --git a/doc/build/changelog/unreleased_14/8019.rst b/doc/build/changelog/unreleased_14/8019.rst
new file mode 100644 (file)
index 0000000..854703b
--- /dev/null
@@ -0,0 +1,7 @@
+.. change::
+    :tags: bug, engine, tests
+    :tickets: 8019
+
+    Fixed issue where support for logging "stacklevel" implemented in
+    :ticket:`7612` required adjustment to work with recently released Python
+    3.11.0b1, also repairs the unit tests which tested this feature.
index fe3bfa1adfcc1c9ffd62b51afa665d7bb1679b46..80e458e7c0094d2c2dc193269388a13456c74650 100644 (file)
@@ -187,8 +187,8 @@ class Connection(ConnectionEventsTarget, inspection.Inspectable["Inspector"]):
         if fmt:
             message = fmt(message)
 
-        if util.py38:
-            kw["stacklevel"] = 2
+        if log.STACKLEVEL:
+            kw["stacklevel"] = 1 + log.STACKLEVEL_OFFSET
 
         self.engine.logger.info(message, *arg, **kw)
 
@@ -198,8 +198,8 @@ class Connection(ConnectionEventsTarget, inspection.Inspectable["Inspector"]):
         if fmt:
             message = fmt(message)
 
-        if util.py38:
-            kw["stacklevel"] = 2
+        if log.STACKLEVEL:
+            kw["stacklevel"] = 1 + log.STACKLEVEL_OFFSET
 
         self.engine.logger.debug(message, *arg, **kw)
 
index d463f5b9a3a3a5c6bc1dd61dcf9d8aa2aa82c80c..f7050b93fb88c44b9196e0bbbdaf73e49e3cfa6c 100644 (file)
@@ -29,9 +29,20 @@ from typing import Type
 from typing import TypeVar
 from typing import Union
 
+from .util import py311
 from .util import py38
 from .util.typing import Literal
 
+
+if py38:
+    STACKLEVEL = True
+    # needed as of py3.11.0b1
+    # #8019
+    STACKLEVEL_OFFSET = 2 if py311 else 1
+else:
+    STACKLEVEL = False
+    STACKLEVEL_OFFSET = 0
+
 _IT = TypeVar("_IT", bound="Identified")
 
 _EchoFlagType = Union[None, bool, Literal["debug"]]
@@ -191,8 +202,11 @@ class InstanceLogger:
             selected_level = self.logger.getEffectiveLevel()
 
         if level >= selected_level:
-            if py38:
-                kwargs["stacklevel"] = kwargs.get("stacklevel", 1) + 1
+
+            if STACKLEVEL:
+                kwargs["stacklevel"] = (
+                    kwargs.get("stacklevel", 1) + STACKLEVEL_OFFSET
+                )
 
             self.logger._log(level, msg, args, **kwargs)
 
index 234f823c68212255eab50ba914f4cd3d8398ee02..e63a3e191705c2017c70b5ee50a7906b96f224ef 100644 (file)
@@ -1418,6 +1418,10 @@ class SuiteRequirements(Requirements):
 
         return exclusions.closed()
 
+    @property
+    def asyncio(self):
+        return self.greenlet
+
     @property
     def greenlet(self):
         def go(config):
index 6d41231d98b533d8bc2bba5c2671b8230e9350aa..756b93bb4783960139d2d2efc14fb130401a4c45 100644 (file)
@@ -59,6 +59,7 @@ from .compat import has_refcount_gc as has_refcount_gc
 from .compat import inspect_getfullargspec as inspect_getfullargspec
 from .compat import local_dataclass_fields as local_dataclass_fields
 from .compat import osx as osx
+from .compat import py311 as py311
 from .compat import py38 as py38
 from .compat import py39 as py39
 from .compat import pypy as pypy
index 462d0900f9308693629f6ddbe168849a834e4aa5..23c422bcf406fe9b57ff9e54280d51937ef6fc99 100644 (file)
@@ -1010,6 +1010,8 @@ class AsyncResultTest(EngineFixture):
 
 
 class TextSyncDBAPI(fixtures.TestBase):
+    __requires__ = ("asyncio",)
+
     def test_sync_dbapi_raises(self):
         with expect_raises_message(
             exc.InvalidRequestError,
index 87fcf7e9dc6d011a338f68ff8395b9608be81f53..ba256c4dd7c34d4a4aea44bcb895968508185e24 100644 (file)
@@ -1315,7 +1315,7 @@ class DefaultRequirements(SuiteRequirements):
     def async_dialect(self):
         """dialect makes use of await_() to invoke operations on the DBAPI."""
 
-        return only_on(
+        return self.asyncio + only_on(
             LambdaPredicate(
                 lambda config: config.db.dialect.is_async,
                 "Async dialect required",
diff --git a/tox.ini b/tox.ini
index fb14a9554560cc8db2c749aa5d0b68761ddb27c3..21cdbdf45d10775fabf4c9110e2d7599e3a881db 100644 (file)
--- a/tox.ini
+++ b/tox.ini
@@ -14,8 +14,9 @@ deps=
      pytest>=7.0.0rc1,<8
      pytest-xdist
 
+     # cython and greenlet both not working on 3.11
      # note cython not working for 3.11 at all right now
-     git+https://github.com/python-greenlet/greenlet.git#egg=greenlet; python_version >= '3.11'
+     git+https://github.com/sqlalchemyorg/greenlet/@fix_py311_cpp#egg=greenlet; python_version >= '3.11'
 
      sqlite: .[aiosqlite]
      sqlite_file: .[aiosqlite]
@@ -89,8 +90,11 @@ setenv=
 
     sqlite: SQLITE={env:TOX_SQLITE:--db sqlite}
     sqlite_file: SQLITE={env:TOX_SQLITE_FILE:--db sqlite_file}
+
     py3{,7,8,9,10,11}-sqlite: EXTRA_SQLITE_DRIVERS={env:EXTRA_SQLITE_DRIVERS:--dbdriver sqlite --dbdriver aiosqlite}
+
     py3{,7,8,9}-sqlite_file: EXTRA_SQLITE_DRIVERS={env:EXTRA_SQLITE_DRIVERS:--dbdriver sqlite --dbdriver aiosqlite --dbdriver pysqlcipher}
+
     # omit pysqlcipher for Python 3.10
     py3{,10,11}-sqlite_file: EXTRA_SQLITE_DRIVERS={env:EXTRA_SQLITE_DRIVERS:--dbdriver sqlite --dbdriver aiosqlite}