Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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.3"
__version__ = "0.11.4"

__all__ = ["Database", "DatabaseURL"]
23 changes: 1 addition & 22 deletions databasez/core/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,6 @@

from databasez.types import BatchCallable, BatchCallableResult, DictAny

try: # pragma: no cover
import click

# Extra log info for optional coloured terminal outputs.
LOG_EXTRA = {"color_message": "Query: " + click.style("%s", bold=True) + " Args: %s"}
CONNECT_EXTRA = {"color_message": "Connected to database " + click.style("%s", bold=True)}
DISCONNECT_EXTRA = {
"color_message": "Disconnected from database " + click.style("%s", bold=True)
}
except ImportError: # pragma: no cover
LOG_EXTRA = {}
CONNECT_EXTRA = {}
DISCONNECT_EXTRA = {}


logger = logging.getLogger("databasez")

default_database: type[interfaces.DatabaseBackend]
Expand Down Expand Up @@ -363,7 +348,6 @@ async def connect(self) -> bool:
self._loop = asyncio.get_event_loop()

await self.backend.connect(self.url, **self.options)
logger.info("Connected to database %s", self.url.obscure_password, extra=CONNECT_EXTRA)
self.is_connected = True

if self._global_connection is None:
Expand All @@ -386,7 +370,7 @@ async def disconnect(
# parent_database is injected and should not be specified manually
if not await self.decr_refcount() or force:
if not self.is_connected:
logger.debug("Already disconnected, skipping disconnection")
logger.debug("Already disconnected, skip disconnecting")
return False
if force:
logger.warning("Force disconnect, despite refcount not 0")
Expand All @@ -413,11 +397,6 @@ async def disconnect(
self._global_connection = None
self._connection = None
finally:
logger.info(
"Disconnected from database %s",
self.url.obscure_password,
extra=DISCONNECT_EXTRA,
)
self.is_connected = False
await self.backend.disconnect()
self._loop = None
Expand Down
7 changes: 7 additions & 0 deletions docs/database.md
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,13 @@ If you want more extensive logging when creating a custom overwrite, you can set

By default this is off, to not confuse people.

See `tests/conftest.py` for an example.

## Debugging db connects

If you want to get debug output for successfully connecting to the db, you can pass `echo=True` as argument.


## Links

[esmerald]: https://github.com/dymmond/esmerald
1 change: 1 addition & 0 deletions docs/release-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

- Use monkay.asgi helpers.
- Bump to python>=3.10.
- Reduce noise by removing info log messages when connecting to/disconnecting from a db.

## 0.11.3

Expand Down
3 changes: 3 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from databasez import utils

utils.DATABASEZ_OVERWRITE_LOGGING = True