diff --git a/django-stubs/db/backends/base/base.pyi b/django-stubs/db/backends/base/base.pyi index 774230644..1d37ce726 100644 --- a/django-stubs/db/backends/base/base.pyi +++ b/django-stubs/db/backends/base/base.pyi @@ -8,6 +8,7 @@ from django.db.backends.base.introspection import BaseDatabaseIntrospection from django.db.backends.base.schema import BaseDatabaseSchemaEditor from django.db.backends.base.validation import BaseDatabaseValidation from django.db.backends.utils import CursorDebugWrapper, CursorWrapper +from django.db.transaction import Atomic NO_DB_ALIAS: str @@ -33,11 +34,15 @@ class BaseDatabaseWrapper: force_debug_cursor: bool = ... autocommit: bool = ... in_atomic_block: bool = ... + atomic_blocks: list[Atomic] = ... savepoint_state: int = ... savepoint_ids: Any = ... commit_on_exit: bool = ... needs_rollback: bool = ... + rollback_exc: Exception | None = ... close_at: Any | None = ... + health_check_enabled: bool = ... + health_check_done: bool = ... closed_in_transaction: bool = ... errors_occurred: bool = ... allow_thread_sharing: bool = ... @@ -63,6 +68,8 @@ class BaseDatabaseWrapper: @property def queries(self) -> list[dict[str, str]]: ... def get_connection_params(self) -> None: ... + def get_database_version(self) -> tuple[int, ...]: ... + def check_database_version_supported(self) -> None: ... def get_new_connection(self, conn_params: Any) -> None: ... def init_connection_state(self) -> None: ... def create_cursor(self, name: Any | None = ...) -> None: ... @@ -92,7 +99,10 @@ class BaseDatabaseWrapper: def enable_constraint_checking(self) -> None: ... def check_constraints(self, table_names: Any | None = ...) -> None: ... def is_usable(self) -> None: ... + def close_if_health_check_failed(self) -> None: ... def close_if_unusable_or_obsolete(self) -> None: ... + def inc_thread_sharing(self) -> None: ... + def dec_thread_sharing(self) -> None: ... def validate_thread_sharing(self) -> None: ... def prepare_database(self) -> None: ... def wrap_database_errors(self) -> Any: ... diff --git a/tests/pyright/test_database_wrapper.py b/tests/pyright/test_database_wrapper.py new file mode 100644 index 000000000..a36c3ebf8 --- /dev/null +++ b/tests/pyright/test_database_wrapper.py @@ -0,0 +1,26 @@ +from .base import Result, run_pyright + + +def test_base_database_wrapper_declares_its_public_members() -> None: + """Every public attribute and method BaseDatabaseWrapper defines is visible to the checker.""" + results = run_pyright( + """\ +from django.db import connection + +connection.inc_thread_sharing() +connection.dec_thread_sharing() +connection.check_database_version_supported() +connection.close_if_health_check_failed() +connection.get_database_version() +reveal_type(connection.atomic_blocks) +reveal_type(connection.health_check_done) +reveal_type(connection.health_check_enabled) +reveal_type(connection.rollback_exc) +""" + ) + assert results == [ + Result(type="information", message='Type of "connection.atomic_blocks" is "list[Atomic]"', line=8, column=13), + Result(type="information", message='Type of "connection.health_check_done" is "bool"', line=9, column=13), + Result(type="information", message='Type of "connection.health_check_enabled" is "bool"', line=10, column=13), + Result(type="information", message='Type of "connection.rollback_exc" is "Exception | None"', line=11, column=13), + ]