Skip to content

[BUG] TestClient request mock HttpRequest's body attribute has the wrong type #1675

@ulinja

Description

@ulinja

Describe the bug
The body attribute of the Ninja test client's mocked request object has the wrong data type. The mocked object has type str, while a Django HttpRequest object's body attribute should be a bytestring (type bytes).

This leads to failures in all unit tests using the ninja client where the tested endpoint logic correctly expects the request body to be of type bytes, but the mocked request object incorrectly passes the type str - making tests fail with errors where they should not.

Versions:

  • Python version: 3.14 (all versions affected)
  • Django version: 6.0 (all versions affected)
  • Django-Ninja version: 1.5.3 (all versions affected)
  • Pydantic version: 2.12.5 (all versions affected)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions