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 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
6 changes: 6 additions & 0 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 @@ -16,10 +17,14 @@ 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 @@ -97,6 +102,7 @@ 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: ...
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: ...
13 changes: 12 additions & 1 deletion django-stubs/db/backends/base/features.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ 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

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 +37,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 +62,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 +89,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 +99,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 +114,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,6 +126,11 @@ 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]
Expand Down
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
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
63 changes: 0 additions & 63 deletions scripts/stubtest/allowlist_todo.txt
Original file line number Diff line number Diff line change
Expand Up @@ -963,48 +963,10 @@ django.core.validators.ProhibitNullCharactersValidator.__new__
django.core.validators.RegexValidator.__new__
django.core.validators.StepValueValidator.__new__
django.core.validators.URLValidator.__new__
django.db.backends.base.base.BaseDatabaseWrapper.SchemaEditorClass
django.db.backends.base.base.BaseDatabaseWrapper.client_class
django.db.backends.base.base.BaseDatabaseWrapper.close_if_health_check_failed
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
django.db.backends.base.base.BaseDatabaseWrapper.timezone
django.db.backends.base.base.BaseDatabaseWrapper.timezone_name
django.db.backends.base.base.logger
django.db.backends.base.base.timezone_constructor
django.db.backends.base.creation.BaseDatabaseCreation.log
django.db.backends.base.creation.BaseDatabaseCreation.mark_expected_failures_and_skips
django.db.backends.base.creation.BaseDatabaseCreation.setup_worker_connection
django.db.backends.base.features.BaseDatabaseFeatures.allows_group_by_select_index
django.db.backends.base.features.BaseDatabaseFeatures.create_test_table_with_composite_primary_key
django.db.backends.base.features.BaseDatabaseFeatures.ignores_unnecessary_order_by_in_subqueries
django.db.backends.base.features.BaseDatabaseFeatures.prohibits_null_characters_in_text_exception
django.db.backends.base.features.BaseDatabaseFeatures.requires_compound_order_by_subquery
django.db.backends.base.features.BaseDatabaseFeatures.schema_editor_uses_clientside_param_binding
django.db.backends.base.features.BaseDatabaseFeatures.supports_comments
django.db.backends.base.features.BaseDatabaseFeatures.supports_comments_inline
django.db.backends.base.features.BaseDatabaseFeatures.supports_comparing_boolean_expr
django.db.backends.base.features.BaseDatabaseFeatures.supports_explaining_query_execution
django.db.backends.base.features.BaseDatabaseFeatures.supports_logical_xor
django.db.backends.base.features.BaseDatabaseFeatures.supports_transactions
django.db.backends.base.features.BaseDatabaseFeatures.supports_unlimited_charfield
django.db.backends.base.schema.BaseDatabaseSchemaEditor.add_constraint
django.db.backends.base.schema.BaseDatabaseSchemaEditor.alter_db_table_comment
django.db.backends.base.schema.BaseDatabaseSchemaEditor.remove_constraint
django.db.backends.base.schema.BaseDatabaseSchemaEditor.rename_index
django.db.backends.base.schema.BaseDatabaseSchemaEditor.skip_default_on_alter
django.db.backends.base.schema.BaseDatabaseSchemaEditor.sql_alter_column_comment
django.db.backends.base.schema.BaseDatabaseSchemaEditor.sql_alter_column_no_default_null
django.db.backends.base.schema.BaseDatabaseSchemaEditor.sql_alter_table_comment
django.db.backends.base.schema.BaseDatabaseSchemaEditor.sql_check_constraint
django.db.backends.base.schema.BaseDatabaseSchemaEditor.sql_constraint
django.db.backends.base.schema.BaseDatabaseSchemaEditor.sql_create_unique_index
django.db.backends.base.schema.BaseDatabaseSchemaEditor.sql_delete_constraint
django.db.backends.base.schema.BaseDatabaseSchemaEditor.sql_rename_index
django.db.backends.base.schema.BaseDatabaseSchemaEditor.sql_unique_constraint
django.db.backends.ddl_references.Expressions
django.db.backends.mysql.base
django.db.backends.mysql.features.DatabaseFeatures.allows_auto_pk_0
Expand All @@ -1015,7 +977,6 @@ django.db.backends.mysql.features.DatabaseFeatures.can_release_savepoints
django.db.backends.mysql.features.DatabaseFeatures.can_rename_index
django.db.backends.mysql.features.DatabaseFeatures.can_return_columns_from_insert
django.db.backends.mysql.features.DatabaseFeatures.can_return_rows_from_bulk_insert
django.db.backends.mysql.features.DatabaseFeatures.create_test_table_with_composite_primary_key
django.db.backends.mysql.features.DatabaseFeatures.django_test_skips
django.db.backends.mysql.features.DatabaseFeatures.has_select_for_update_nowait
django.db.backends.mysql.features.DatabaseFeatures.has_select_for_update_of
Expand All @@ -1027,14 +988,11 @@ django.db.backends.mysql.features.DatabaseFeatures.is_sql_auto_is_null_enabled
django.db.backends.mysql.features.DatabaseFeatures.minimum_database_version
django.db.backends.mysql.features.DatabaseFeatures.supported_explain_formats
django.db.backends.mysql.features.DatabaseFeatures.supports_column_check_constraints
django.db.backends.mysql.features.DatabaseFeatures.supports_comments
django.db.backends.mysql.features.DatabaseFeatures.supports_comments_inline
django.db.backends.mysql.features.DatabaseFeatures.supports_default_in_lead_lag
django.db.backends.mysql.features.DatabaseFeatures.supports_explain_analyze
django.db.backends.mysql.features.DatabaseFeatures.supports_expression_indexes
django.db.backends.mysql.features.DatabaseFeatures.supports_frame_range_fixed_distance
django.db.backends.mysql.features.DatabaseFeatures.supports_index_column_ordering
django.db.backends.mysql.features.DatabaseFeatures.supports_logical_xor
django.db.backends.mysql.features.DatabaseFeatures.supports_over_clause
django.db.backends.mysql.features.DatabaseFeatures.supports_select_difference
django.db.backends.mysql.features.DatabaseFeatures.supports_select_intersection
Expand All @@ -1044,24 +1002,12 @@ django.db.backends.mysql.features.DatabaseFeatures.test_collations
django.db.backends.mysql.features.DatabaseFeatures.update_can_self_select
django.db.backends.mysql.features.DatabaseFeatures.uses_savepoints
django.db.backends.mysql.introspection
django.db.backends.mysql.schema.DatabaseSchemaEditor.remove_constraint
django.db.backends.mysql.schema.DatabaseSchemaEditor.skip_default_on_alter
django.db.backends.mysql.schema.DatabaseSchemaEditor.sql_alter_column_comment
django.db.backends.mysql.schema.DatabaseSchemaEditor.sql_alter_column_no_default_null
django.db.backends.mysql.schema.DatabaseSchemaEditor.sql_alter_table_comment
django.db.backends.mysql.schema.DatabaseSchemaEditor.sql_rename_index
django.db.backends.oracle.base
django.db.backends.oracle.features.DatabaseFeatures.allows_group_by_select_index
django.db.backends.oracle.features.DatabaseFeatures.create_test_table_with_composite_primary_key
django.db.backends.oracle.features.DatabaseFeatures.ignores_unnecessary_order_by_in_subqueries
django.db.backends.oracle.features.DatabaseFeatures.introspected_field_types
django.db.backends.oracle.features.DatabaseFeatures.requires_compound_order_by_subquery
django.db.backends.oracle.features.DatabaseFeatures.supports_collation_on_charfield
django.db.backends.oracle.features.DatabaseFeatures.supports_comments
django.db.backends.oracle.features.DatabaseFeatures.supports_comparing_boolean_expr
django.db.backends.oracle.introspection
django.db.backends.oracle.operations
django.db.backends.oracle.schema.DatabaseSchemaEditor.sql_alter_column_no_default_null
django.db.backends.oracle.utils
django.db.backends.postgresql.base.DatabaseWrapper.Database
django.db.backends.postgresql.base.DatabaseWrapper.ensure_role
Expand All @@ -1073,7 +1019,6 @@ django.db.backends.postgresql.base.INETARRAY_OID
django.db.backends.postgresql.base.PSYCOPG2_VERSION
django.db.backends.postgresql.base.psycopg2_version
django.db.backends.postgresql.base.psycopg_version
django.db.backends.postgresql.features.DatabaseFeatures.create_test_table_with_composite_primary_key
django.db.backends.postgresql.features.DatabaseFeatures.django_test_expected_failures
django.db.backends.postgresql.features.DatabaseFeatures.has_bit_xor
django.db.backends.postgresql.features.DatabaseFeatures.introspected_field_types
Expand All @@ -1083,10 +1028,7 @@ django.db.backends.postgresql.features.DatabaseFeatures.is_postgresql_12
django.db.backends.postgresql.features.DatabaseFeatures.is_postgresql_13
django.db.backends.postgresql.features.DatabaseFeatures.is_postgresql_14
django.db.backends.postgresql.features.DatabaseFeatures.prohibits_null_characters_in_text_exception
django.db.backends.postgresql.features.DatabaseFeatures.schema_editor_uses_clientside_param_binding
django.db.backends.postgresql.features.DatabaseFeatures.supports_comments
django.db.backends.postgresql.features.DatabaseFeatures.supports_covering_spgist_indexes
django.db.backends.postgresql.features.DatabaseFeatures.supports_unlimited_charfield
django.db.backends.postgresql.features.DatabaseFeatures.uses_server_side_binding
django.db.backends.postgresql.introspection.DatabaseIntrospection.index_default_access_method
django.db.backends.postgresql.introspection.FieldInfo
Expand All @@ -1105,24 +1047,19 @@ django.db.backends.sqlite3.base.SQLiteCursorWrapper.executemany
django.db.backends.sqlite3.base.adapt_date
django.db.backends.sqlite3.base.adapt_datetime
django.db.backends.sqlite3.base.check_sqlite_version
django.db.backends.sqlite3.creation.DatabaseCreation.setup_worker_connection
django.db.backends.sqlite3.features.DatabaseFeatures.can_alter_table_drop_column
django.db.backends.sqlite3.features.DatabaseFeatures.can_alter_table_rename_column
django.db.backends.sqlite3.features.DatabaseFeatures.can_introspect_json_field
django.db.backends.sqlite3.features.DatabaseFeatures.can_return_columns_from_insert
django.db.backends.sqlite3.features.DatabaseFeatures.can_return_rows_from_bulk_insert
django.db.backends.sqlite3.features.DatabaseFeatures.create_test_table_with_composite_primary_key
django.db.backends.sqlite3.features.DatabaseFeatures.django_test_skips
django.db.backends.sqlite3.features.DatabaseFeatures.has_json_object_function
django.db.backends.sqlite3.features.DatabaseFeatures.introspected_field_types
django.db.backends.sqlite3.features.DatabaseFeatures.requires_compound_order_by_subquery
django.db.backends.sqlite3.features.DatabaseFeatures.supports_atomic_references_rename
django.db.backends.sqlite3.features.DatabaseFeatures.supports_json_field
django.db.backends.sqlite3.introspection.FieldInfo
django.db.backends.sqlite3.schema.DatabaseSchemaEditor.add_constraint
django.db.backends.sqlite3.schema.DatabaseSchemaEditor.alter_db_table
django.db.backends.sqlite3.schema.DatabaseSchemaEditor.delete_model
django.db.backends.sqlite3.schema.DatabaseSchemaEditor.remove_constraint
django.db.backends.sqlite3.schema.DatabaseSchemaEditor.sql_create_fk
django.db.backends.utils.debug_transaction
django.db.backends.utils.names_digest
Expand Down