You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When we delete a certain object, we also want to delete some related objects and we want this to be visible in the Delete Confirmation View.
I got some typing issues regarding an override I did for get_deleted_objects(self, objs, request) in a subclass to admin.ModelAdmin.
Looking at the Django documentation for this method it is said to return tuple[list[str], dict[str, int], set[str], list[str]].
I also verified this in a debug session where the deleted_objects value was: 'Parameter set: <a href="/admin/onboard/parameterset/341/change/">341</a>'.
However, in django_stubs.contrib.admin.options.ModelAdmin.get_deleted_objects I see the the deleted_objects is typed as list[Model]. The full return type is specified as tuple[list[Model], dict[str, int], set[str], list[str]].
I rely on this being a list[str] as I append strings to this list using django.utils.html.format_html, which fails with the current definition using a list[Model].
Just some example code to easier understand the issue (Not verified if this exact code raises the issue):
Return type "tuple[list[str], dict[str, int], set[str], list[str]]" of "get_deleted_objects" incompatible with return type "tuple[list[Model], dict[str, int], set[str], list[str]]" in supertype "ModelAdmin"
Just changing it to list[Model] doesn't work in this case, as the I get:
Argument 1 to "append" of "list" has incompatible type "SafeString"; expected "Model"
How is that should be
The return type of admin.ModelAdmin.get_deleted_objects should be changed from:
Bug report
What's wrong
When we delete a certain object, we also want to delete some related objects and we want this to be visible in the Delete Confirmation View.
I got some typing issues regarding an override I did for
get_deleted_objects(self, objs, request)
in a subclass toadmin.ModelAdmin
.Looking at the Django documentation for this method it is said to return
tuple[list[str], dict[str, int], set[str], list[str]]
.I also verified this in a debug session where the
deleted_objects
value was:'Parameter set: <a href="/admin/onboard/parameterset/341/change/">341</a>'
.However, in
django_stubs.contrib.admin.options.ModelAdmin.get_deleted_objects
I see the the deleted_objects is typed aslist[Model]
. The full return type is specified astuple[list[Model], dict[str, int], set[str], list[str]]
.I rely on this being a
list[str]
as I append strings to this list usingdjango.utils.html.format_html
, which fails with the current definition using alist[Model]
.Just some example code to easier understand the issue (Not verified if this exact code raises the issue):
This would return a mypy-error:
Just changing it to list[Model] doesn't work in this case, as the I get:
How is that should be
The return type of
admin.ModelAdmin.get_deleted_objects
should be changed from:System information
python
version: 3.11.6django
version: 4.2.7mypy
version: 1.6.1django-stubs
version: 4.2.6django-stubs-ext
version: 4.2.5The text was updated successfully, but these errors were encountered: