diff --git a/django-stubs/db/models/base.pyi b/django-stubs/db/models/base.pyi index 72ba99d198..cca3aeca0c 100644 --- a/django-stubs/db/models/base.pyi +++ b/django-stubs/db/models/base.pyi @@ -19,14 +19,14 @@ class ModelState: fields_cache: ModelStateFieldsCacheDescriptor class ModelBase(type): - @property - def objects(cls: type[_Self]) -> BaseManager[_Self]: ... # type: ignore[misc] @property def _default_manager(cls: type[_Self]) -> BaseManager[_Self]: ... # type: ignore[misc] @property def _base_manager(cls: type[_Self]) -> BaseManager[_Self]: ... # type: ignore[misc] class Model(metaclass=ModelBase): + objects: BaseManager[Self] + DoesNotExist: Final[type[ObjectDoesNotExist]] MultipleObjectsReturned: Final[type[BaseMultipleObjectsReturned]] diff --git a/scripts/stubtest/allowlist_todo.txt b/scripts/stubtest/allowlist_todo.txt index 7efa0d6851..6e8b4c38f2 100644 --- a/scripts/stubtest/allowlist_todo.txt +++ b/scripts/stubtest/allowlist_todo.txt @@ -331,17 +331,13 @@ django.contrib.gis.db.backends.oracle.features.DatabaseFeatures.supports_toleran django.contrib.gis.db.backends.oracle.features.DatabaseFeatures.unsupported_geojson_options django.contrib.gis.db.backends.oracle.introspection django.contrib.gis.db.backends.oracle.models.OracleGeometryColumns.Meta -django.contrib.gis.db.backends.oracle.models.OracleGeometryColumns.objects django.contrib.gis.db.backends.oracle.models.OracleSpatialRefSys.Meta -django.contrib.gis.db.backends.oracle.models.OracleSpatialRefSys.objects django.contrib.gis.db.backends.oracle.operations django.contrib.gis.db.backends.postgis.adapter.PostGISAdapter.prepare django.contrib.gis.db.backends.postgis.features.DatabaseFeatures.empty_intersection_returns_none django.contrib.gis.db.backends.postgis.features.DatabaseFeatures.supports_geography django.contrib.gis.db.backends.postgis.models.PostGISGeometryColumns.Meta -django.contrib.gis.db.backends.postgis.models.PostGISGeometryColumns.objects django.contrib.gis.db.backends.postgis.models.PostGISSpatialRefSys.Meta -django.contrib.gis.db.backends.postgis.models.PostGISSpatialRefSys.objects django.contrib.gis.db.backends.postgis.operations.PostGISOperations.convert_extent django.contrib.gis.db.backends.postgis.operations.PostGISOperations.convert_extent3d django.contrib.gis.db.backends.postgis.operations.PostGISOperator.check_geography @@ -351,9 +347,7 @@ django.contrib.gis.db.backends.spatialite.features.DatabaseFeatures.can_alter_ge django.contrib.gis.db.backends.spatialite.features.DatabaseFeatures.django_test_skips django.contrib.gis.db.backends.spatialite.features.DatabaseFeatures.supports_area_geodetic django.contrib.gis.db.backends.spatialite.models.SpatialiteGeometryColumns.Meta -django.contrib.gis.db.backends.spatialite.models.SpatialiteGeometryColumns.objects django.contrib.gis.db.backends.spatialite.models.SpatialiteSpatialRefSys.Meta -django.contrib.gis.db.backends.spatialite.models.SpatialiteSpatialRefSys.objects django.contrib.gis.db.backends.spatialite.operations.SpatiaLiteOperations.convert_extent django.contrib.gis.db.backends.spatialite.operations.SpatiaLiteOperations.from_text django.contrib.gis.db.backends.spatialite.operations.SpatiaLiteOperations.geom_lib_version @@ -1295,7 +1289,6 @@ django.db.migrations.questioner.NonInteractiveMigrationQuestioner.log_lack_of_mi django.db.migrations.recorder.MigrationRecorder.Migration.get_next_by_applied django.db.migrations.recorder.MigrationRecorder.Migration.get_previous_by_applied django.db.migrations.recorder.MigrationRecorder.Migration.id -django.db.migrations.recorder.MigrationRecorder.Migration.objects django.db.migrations.serializer.ChoicesSerializer django.db.migrations.utils.FieldReference django.db.migrations.utils.field_is_referenced @@ -1556,7 +1549,6 @@ django.db.models.base.Model.Meta django.db.models.base.Model.add_to_class django.db.models.base.ModelBase.__new__ django.db.models.base.ModelBase.add_to_class -django.db.models.base.ModelBase.objects django.db.models.base.ModelStateFieldsCacheDescriptor.__get__ django.db.models.base.make_foreign_order_accessors django.db.models.base.method_get_order diff --git a/tests/typecheck/models/test_abstract.yml b/tests/typecheck/models/test_abstract.yml index dfaff3b424..2e85d00fdb 100644 --- a/tests/typecheck/models/test_abstract.yml +++ b/tests/typecheck/models/test_abstract.yml @@ -51,6 +51,7 @@ Recursive(parent=Recursive(parent=None)) Concrete(parent=Concrete(parent=None)) out: | + main:4: error: Access to generic instance variables via class is ambiguous main:4: error: Unexpected attribute "parent" for model "Recursive" main:4: error: Cannot instantiate abstract model "Recursive" main:5: error: Unexpected attribute "parent" for model "Recursive" diff --git a/tests/typecheck/models/test_meta_options.yml b/tests/typecheck/models/test_meta_options.yml index 2a9518a891..3a1013bbf3 100644 --- a/tests/typecheck/models/test_meta_options.yml +++ b/tests/typecheck/models/test_meta_options.yml @@ -79,8 +79,12 @@ MyModel.objects.create(field=2) # Errors: - AbstractModel() # E: Cannot instantiate abstract model "AbstractModel" - AbstractModel.objects.create() # E: Cannot instantiate abstract model "AbstractModel" + AbstractModel() + AbstractModel.objects.create() + out: | + main:8: error: Cannot instantiate abstract model "AbstractModel" + main:9: error: Access to generic instance variables via class is ambiguous + main:9: error: Cannot instantiate abstract model "AbstractModel" installed_apps: - myapp files: