diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0b092b1..90b1762 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,7 +2,7 @@ # See https://pre-commit.com/hooks.html for more hooks. repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.6.0 + rev: v5.0.0 hooks: - id: check-added-large-files - id: check-toml @@ -13,7 +13,7 @@ repos: - id: end-of-file-fixer - id: trailing-whitespace - repo: https://github.com/charliermarsh/ruff-pre-commit - rev: v0.10.0 + rev: v0.11.8 hooks: - id: ruff args: ["--fix"] diff --git a/databasez/__init__.py b/databasez/__init__.py index f0ebcb3..79f1807 100644 --- a/databasez/__init__.py +++ b/databasez/__init__.py @@ -1,5 +1,5 @@ from databasez.core import Database, DatabaseURL -__version__ = "0.11.2" +__version__ = "0.11.3" __all__ = ["Database", "DatabaseURL"] diff --git a/databasez/core/database.py b/databasez/core/database.py index b311a7e..8cfd88d 100644 --- a/databasez/core/database.py +++ b/databasez/core/database.py @@ -12,9 +12,8 @@ from types import TracebackType from typing import TYPE_CHECKING, Any, cast, overload -from databasez import interfaces +from databasez import interfaces, utils from databasez.utils import ( - DATABASEZ_POLL_INTERVAL, _arun_with_timeout, arun_coroutine_threadsafe, multiloop_protector, @@ -219,7 +218,7 @@ def __init__( force_rollback: bool | None = None, config: DictAny | None = None, full_isolation: bool | None = None, - # for + # for custom poll intervals poll_interval: float | None = None, **options: Any, ): @@ -252,7 +251,8 @@ def __init__( if full_isolation is None: full_isolation = False if poll_interval is None: - poll_interval = DATABASEZ_POLL_INTERVAL + # when not using utils...., the constant cannot be changed at runtime + poll_interval = utils.DATABASEZ_POLL_INTERVAL self.poll_interval = poll_interval self._full_isolation = full_isolation self._force_rollback = ForceRollback(force_rollback) @@ -622,14 +622,16 @@ def get_backends( type[interfaces.TransactionBackend], ]: module: Any = None + # when not using utils...., the constant cannot be changed at runtime for debug purposes + more_debug = utils.DATABASEZ_OVERWRITE_LOGGING for overwrite_path in overwrite_paths: imp_path = f"{overwrite_path}.{scheme.replace('+', '_')}" if scheme else overwrite_path try: module = importlib.import_module(imp_path) except ImportError as exc: logging.debug( - f'Import of "{imp_path}" failed. This is not an error.', - exc_info=exc, + f'Could not import "{imp_path}". Continue search.', + exc_info=exc if more_debug else None, ) if "+" in scheme: imp_path = f"{overwrite_path}.{scheme.split('+', 1)[0]}" @@ -637,11 +639,15 @@ def get_backends( module = importlib.import_module(imp_path) except ImportError as exc: logging.debug( - f'Import of "{imp_path}" failed. This is not an error.', - exc_info=exc, + f'Could not import "{imp_path}". Continue search.', + exc_info=exc if more_debug else None, ) if module is not None: break + if module is None: + logging.debug( + "No overwrites found. Use default.", + ) database_class = getattr(module, database_name, database_class) assert database_class is not None and issubclass( database_class, interfaces.DatabaseBackend diff --git a/databasez/utils.py b/databasez/utils.py index cf3f7d0..684da8d 100644 --- a/databasez/utils.py +++ b/databasez/utils.py @@ -11,6 +11,7 @@ from sqlalchemy.engine import Connection as SQLAConnection from sqlalchemy.engine import Dialect +DATABASEZ_OVERWRITE_LOGGING: bool = False DATABASEZ_RESULT_TIMEOUT: float | None = None # Poll with 0.1ms, this way CPU isn't at 100% DATABASEZ_POLL_INTERVAL: float = 0.0001 diff --git a/docs/database.md b/docs/database.md index 2545382..9daac82 100644 --- a/docs/database.md +++ b/docs/database.md @@ -270,6 +270,14 @@ Sometimes there is a lockup. To get of the underlying issues, you can set This way lockups will raise an exception. +## Debugging overwrites + +If you want more extensive logging when creating a custom overwrite, you can set + +`databasez.utils.DATABASEZ_OVERWRITE_LOGGING` to `True` to enable stack traces for import errors in debug messages. + +By default this is off, to not confuse people. + ## Links [esmerald]: https://github.com/dymmond/esmerald diff --git a/docs/release-notes.md b/docs/release-notes.md index e8893e0..49dc17d 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -1,5 +1,12 @@ # Release Notes +## 0.11.3 + +### Fixed + +- Excessive and confusing debug logging for overwrite selection. +- Allow `DATABASEZ_POLL_INTERVAL` overwrites. + ## 0.11.2 ### Fixed diff --git a/pyproject.toml b/pyproject.toml index 93369ee..0e0c8f4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -193,7 +193,7 @@ check_types = "mypy -p databasez" [tool.hatch.envs.hatch-static-analysis] # disables custom ruff rules, required to align with pre-commit config-path = "none" -dependencies = ["ruff==0.10.0"] +dependencies = ["ruff==0.11.8"] [tool.hatch.envs.hatch-test]