Skip to content

Recent change to admin action decorators bans return values #1330

@christianbundy

Description

@christianbundy

Bug report

Example code:

@admin.action(description="get some JSON")
def get_json(
    self,
    request: HttpRequest,
    queryset: QuerySet[SomeModel],
) -> HttpResponse:       
    return HttpResponse(
        json.dumps({"some": "json"}),
        "application/json",
        status.HTTP_200_OK,
    )

What's wrong

In older versions of django-stubs, this code was fine, because @admin.action was typed as:

def action(
    function: Callable[[ModelAdmin, HttpRequest, QuerySet], None] | None = ...,
    *,
    permissions: Sequence[str] | None = ...,
    description: str | None = ...,
) -> Callable: ...

But in #1267, this was changed to hard-code the return value as None.

How is that should be

I'm not 100% sure what return values Django allows, but I think this should at least allow HTTP responses.

Link: https://docs.djangoproject.com/en/4.1/ref/contrib/admin/actions/#actions-that-provide-intermediate-pages

System information

  • OS: Linux
  • python version: 3.10.8
  • django version: 4.0.8
  • mypy version: 0.982
  • django-stubs version: 1.13.2
  • django-stubs-ext version: 0.7.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingregressionBehavior has changed for worse with a releasestubsIssues in stubs files (.pyi)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions