Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Django db backend base wrapper #1791

Merged
Merged
Show file tree
Hide file tree
Changes from 4 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
12 changes: 9 additions & 3 deletions django-stubs/db/backends/base/base.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from collections.abc import Callable, Generator, Iterator, MutableMapping
from contextlib import contextmanager
from datetime import tzinfo
from logging import Logger
from typing import Any

from django.db.backends.base.client import BaseDatabaseClient
Expand All @@ -11,15 +12,19 @@ from django.db.backends.base.operations import BaseDatabaseOperations
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.utils.functional import cached_property
from typing_extensions import Self, TypeAlias

NO_DB_ALIAS: str
RAN_DB_VERSION_CHECK: set[str]

logger: Logger
UnknownPlatypus marked this conversation as resolved.
Show resolved Hide resolved
_ExecuteWrapper: TypeAlias = Callable[
[Callable[[str, Any, bool, dict[str, Any]], Any], str, Any, bool, dict[str, Any]], Any
]

def timezone_constructor(tzname: str) -> tzinfo: ...

class BaseDatabaseWrapper:
data_types: dict[str, str]
data_types_suffix: dict[str, str]
Expand Down Expand Up @@ -60,9 +65,9 @@ class BaseDatabaseWrapper:
operators: MutableMapping[str, str]
def __init__(self, settings_dict: dict[str, Any], alias: str = ...) -> None: ...
def ensure_timezone(self) -> bool: ...
@property
@cached_property
UnknownPlatypus marked this conversation as resolved.
Show resolved Hide resolved
def timezone(self) -> tzinfo | None: ...
@property
@cached_property
def timezone_name(self) -> str: ...
@property
def queries_logged(self) -> bool: ...
Expand Down Expand Up @@ -97,14 +102,15 @@ class BaseDatabaseWrapper:
def enable_constraint_checking(self) -> None: ...
def check_constraints(self, table_names: Any | None = ...) -> None: ...
def is_usable(self) -> bool: ...
def close_if_health_check_failed(self) -> None: ...
def close_if_unusable_or_obsolete(self) -> None: ...
@property
def allow_thread_sharing(self) -> bool: ...
def inc_thread_sharing(self) -> None: ...
def dec_thread_sharing(self) -> None: ...
def validate_thread_sharing(self) -> None: ...
def prepare_database(self) -> None: ...
@property
@cached_property
def wrap_database_errors(self) -> Any: ...
def chunked_cursor(self) -> CursorWrapper: ...
def make_debug_cursor(self, cursor: CursorWrapper) -> CursorDebugWrapper: ...
Expand Down
3 changes: 3 additions & 0 deletions django-stubs/db/backends/base/creation.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ TEST_DATABASE_PREFIX: str
class BaseDatabaseCreation:
connection: BaseDatabaseWrapper
def __init__(self, connection: BaseDatabaseWrapper) -> None: ...
def log(self, msg: str) -> None: ...
def create_test_db(
self, verbosity: int = ..., autoclobber: bool = ..., serialize: bool = ..., keepdb: bool = ...
) -> str: ...
Expand All @@ -22,5 +23,7 @@ class BaseDatabaseCreation:
keepdb: bool = ...,
suffix: str | None = ...,
) -> None: ...
def mark_expected_failures_and_skips(self) -> None: ...
def sql_table_creation_suffix(self) -> str: ...
def test_db_signature(self) -> tuple[str, str, str, str]: ...
def setup_worker_connection(self, _worker_id: int) -> None: ...
18 changes: 15 additions & 3 deletions django-stubs/db/backends/base/features.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ from typing import Any

from django.db.backends.base.base import BaseDatabaseWrapper
from django.db.models.base import Model
from django.db.utils import DatabaseError
from django.db.utils import DatabaseError, DataError
from django.utils.functional import cached_property

class BaseDatabaseFeatures:
minimum_database_version: tuple[int, ...] | None
gis_enabled: bool
allows_group_by_lob: bool
allows_group_by_selected_pks: bool
allows_group_by_select_index: bool
empty_fetchmany_value: Sequence[Any]
update_can_self_select: bool
interprets_empty_strings_as_nulls: bool
Expand All @@ -36,6 +38,7 @@ class BaseDatabaseFeatures:
truncates_names: bool
has_real_datatype: bool
supports_subqueries_in_group_by: bool
ignores_unnecessary_order_by_in_subqueries: bool
has_native_uuid_field: bool
has_native_duration_field: bool
supports_temporal_subtraction: bool
Expand All @@ -60,6 +63,7 @@ class BaseDatabaseFeatures:
can_distinct_on_fields: bool
atomic_transactions: bool
can_rollback_ddl: bool
schema_editor_uses_clientside_param_binding: bool
supports_atomic_references_rename: bool
supports_combined_alters: bool
supports_foreign_keys: bool
Expand All @@ -86,6 +90,7 @@ class BaseDatabaseFeatures:
supports_select_difference: bool
supports_slicing_ordering_in_compound: bool
supports_parentheses_in_compound: bool
requires_compound_order_by_subquery: bool
supports_aggregate_filter_clause: bool
supports_index_on_text_field: bool
supports_over_clause: bool
Expand All @@ -95,6 +100,7 @@ class BaseDatabaseFeatures:
time_cast_precision: int
create_test_procedure_without_params_sql: str | None
create_test_procedure_with_int_param_sql: str | None
create_test_table_with_composite_primary_key: str | None
supports_callproc_kwargs: bool
supported_explain_formats: set[str]
supports_default_in_lead_lag: bool
Expand All @@ -109,6 +115,7 @@ class BaseDatabaseFeatures:
collate_as_index_expression: bool
allows_multiple_constraints_on_same_fields: bool
supports_boolean_expr_in_select_clause: bool
supports_comparing_boolean_expr: bool
supports_json_field: bool
can_introspect_json_field: bool
supports_primitives_in_json_field: bool
Expand All @@ -120,14 +127,19 @@ class BaseDatabaseFeatures:
supports_collation_on_charfield: bool
supports_collation_on_textfield: bool
supports_non_deterministic_collations: bool
supports_comments: bool
supports_comments_inline: bool
supports_logical_xor: bool
prohibits_null_characters_in_text_exception: tuple[ValueError | DataError] | None
supports_unlimited_charfield: bool
test_collations: dict[str, str | None]
test_now_utc_template: str | None
django_test_expected_failures: set[str]
django_test_skips: dict[str, set[str]]
connection: BaseDatabaseWrapper
def __init__(self, connection: BaseDatabaseWrapper) -> None: ...
@property
@cached_property
def supports_explaining_query_execution(self) -> bool: ...
@property
@cached_property
UnknownPlatypus marked this conversation as resolved.
Show resolved Hide resolved
def supports_transactions(self) -> bool: ...
def allows_group_by_selected_pks_on_model(self, model: type[Model]) -> bool: ...
17 changes: 17 additions & 0 deletions django-stubs/db/backends/base/schema.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ from typing import Any
from django.db.backends.base.base import BaseDatabaseWrapper
from django.db.backends.ddl_references import Statement
from django.db.models.base import Model
from django.db.models.constraints import BaseConstraint
from django.db.models.fields import Field
from django.db.models.indexes import Index
from typing_extensions import Self
Expand All @@ -25,9 +26,14 @@ class BaseDatabaseSchemaEditor(AbstractContextManager[Any]):
sql_alter_column_not_null: str
sql_alter_column_default: str
sql_alter_column_no_default: str
sql_alter_column_no_default_null: str
sql_delete_column: str
sql_rename_column: str
sql_update_with_default: str
sql_unique_constraint: str
sql_check_constraint: str
sql_delete_constraint: str
sql_constraint: str
sql_create_check: str
sql_delete_check: str
sql_create_unique: str
Expand All @@ -39,10 +45,14 @@ class BaseDatabaseSchemaEditor(AbstractContextManager[Any]):
sql_delete_fk: str

sql_create_index: str
sql_create_unique_index: str
sql_rename_index: str
sql_delete_index: str
sql_create_pk: str
sql_delete_pk: str
sql_delete_procedure: str
sql_alter_table_comment: str
sql_alter_column_comment: str
connection: BaseDatabaseWrapper
collect_sql: bool
collected_sql: Any
Expand All @@ -64,13 +74,17 @@ class BaseDatabaseSchemaEditor(AbstractContextManager[Any]):
self, model: type[Model], field: Field, include_default: bool = ...
) -> tuple[None, None] | tuple[str, list[Any]]: ...
def skip_default(self, field: Any) -> bool: ...
def skip_default_on_alter(self, field: Any) -> bool: ...
def prepare_default(self, value: Any) -> Any: ...
def effective_default(self, field: Field) -> int | str: ...
def quote_value(self, value: Any) -> str: ...
def create_model(self, model: type[Model]) -> None: ...
def delete_model(self, model: type[Model]) -> None: ...
def add_index(self, model: type[Model], index: Index) -> None: ...
def remove_index(self, model: type[Model], index: Index) -> None: ...
def rename_index(self, model: type[Model], old_index: Index, new_index: Index) -> None: ...
def add_constraint(self, model: type[Model], constraint: BaseConstraint) -> None: ...
def remove_constraint(self, model: type[Model], constraint: BaseConstraint) -> None: ...
def alter_unique_together(
self,
model: type[Model],
Expand All @@ -84,6 +98,9 @@ class BaseDatabaseSchemaEditor(AbstractContextManager[Any]):
new_index_together: Sequence[Sequence[str]],
) -> None: ...
def alter_db_table(self, model: type[Model], old_db_table: str, new_db_table: str) -> None: ...
def alter_db_table_comment(
self, model: type[Model], old_db_table_comment: str | None, new_db_table_comment: str
) -> None: ...
def alter_db_tablespace(self, model: Any, old_db_tablespace: Any, new_db_tablespace: Any) -> None: ...
def add_field(self, model: Any, field: Any) -> None: ...
def remove_field(self, model: Any, field: Any) -> None: ...
Expand Down
2 changes: 1 addition & 1 deletion django-stubs/db/backends/dummy/features.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.db.backends.base.features import BaseDatabaseFeatures

class DummyDatabaseFeatures(BaseDatabaseFeatures):
supports_transactions: bool
supports_transactions: bool # type: ignore[assignment]
UnknownPlatypus marked this conversation as resolved.
Show resolved Hide resolved
uses_savepoints: bool
3 changes: 2 additions & 1 deletion django-stubs/db/backends/mysql/features.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ from typing import Any

from django.db.backends.base.features import BaseDatabaseFeatures
from django.db.backends.mysql.base import DatabaseWrapper
from django.utils.functional import cached_property

class DatabaseFeatures(BaseDatabaseFeatures):
connection: DatabaseWrapper
Expand Down Expand Up @@ -71,7 +72,7 @@ class DatabaseFeatures(BaseDatabaseFeatures):
def supports_explain_analyze(self) -> bool: ...
@property
def supported_explain_formats(self) -> set[str]: ... # type: ignore[override]
@property
@cached_property
def supports_transactions(self) -> bool: ...
@property
def ignores_table_name_case(self) -> bool: ... # type: ignore[override]
Expand Down
2 changes: 1 addition & 1 deletion django-stubs/db/backends/oracle/features.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class DatabaseFeatures(BaseDatabaseFeatures):
can_return_columns_from_insert: bool
can_introspect_autofield: bool
supports_subqueries_in_group_by: bool
supports_transactions: bool
supports_transactions: bool # type: ignore[assignment]
supports_timezones: bool
has_native_duration_field: bool
can_defer_constraint_checks: bool
Expand Down
2 changes: 1 addition & 1 deletion django-stubs/db/backends/postgresql/features.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class DatabaseFeatures(BaseDatabaseFeatures):
has_select_for_no_key_update: bool
can_release_savepoints: bool
supports_tablespaces: bool
supports_transactions: bool
supports_transactions: bool # type: ignore[assignment]
can_introspect_materialized_views: bool
can_distinct_on_fields: bool
can_rollback_ddl: bool
Expand Down
12 changes: 11 additions & 1 deletion scripts/stubtest/allowlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,20 @@ django.utils.translation.template.block_re
django.utils.version.version_component_re
django.views.debug.SafeExceptionReporterFilter.hidden_settings

# AlterTogetherOptionsOperation.option_name is set as None,
# AlterTogetherOptionOperation.option_name is set as None,
# but is required in the init, so we type it as str
django.db.migrations.operations.models.AlterTogetherOptionOperation.option_name

# These are set to None in the base class but *must* be overridden
# because they are required in the init, so we type them without the None option.
django.db.backends.base.base.BaseDatabaseWrapper.SchemaEditorClass
django.db.backends.base.base.BaseDatabaseWrapper.client_class
django.db.backends.base.base.BaseDatabaseWrapper.creation_class
django.db.backends.base.base.BaseDatabaseWrapper.features_class
django.db.backends.base.base.BaseDatabaseWrapper.introspection_class
django.db.backends.base.base.BaseDatabaseWrapper.ops
django.db.backends.base.base.BaseDatabaseWrapper.ops_class

# Attributes defaulting to None messing with mypy
django.views.generic.detail.SingleObjectMixin.model
django.views.generic.edit.BaseDeleteView.form_class
Expand Down
Loading