Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"]
Expand Down
2 changes: 1 addition & 1 deletion databasez/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from databasez.core import Database, DatabaseURL

__version__ = "0.11.2"
__version__ = "0.11.3"

__all__ = ["Database", "DatabaseURL"]
22 changes: 14 additions & 8 deletions databasez/core/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
):
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -622,26 +622,32 @@ 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]}"
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 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
Expand Down
1 change: 1 addition & 0 deletions databasez/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions docs/database.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 7 additions & 0 deletions docs/release-notes.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down