TGViewer
Находки в опенсорсе: Python Находки в опенсорсе: Python @opensource_findings_python · 1.06K subscribers
Post #304 162
🚀 New issue to wemake-services/django-modern-rest by @kondratevdev
📝 Strict boolean `Query` component cannot parse valid OpenAPI boolean values (#1325)


What's wrong?

Boolean query parameters cannot be parsed correctly when using Pydantic strict validation, even though DMR generates a valid OpenAPI schema for them.

For example:

from pydantic import BaseModel, StrictBool

class ProjectsQuery(BaseModel):
random: StrictBool = False

DMR generates the expected OpenAPI schema:

- name: random
in: query
schema:
type: boolean
default: false

However, a valid request:

GET /projects?random=false

is rejected with 400 Bad Request:

{
"detail": [
{
"msg": "Input should be a valid boolean",
"loc": ["parsed_query", "random"],
"type": "value_error"
}
]
}

Schemathesis detects this as a schema-compliant request being rejected:

API rejected schema-compliant request

Valid data should have been accepted
Expected: 2xx, 401, 403, 404, 409, 5xx
[400] Bad Request Reproduce with: curl -X GET --insecure \ 'http://localhost/api/projects/projects/?random=false'

Why not use a regular bool?

A regular Pydantic bool successfully parses query parameters:

class ProjectsQuery(BaseModel):
random: bool = False

So these work as expected:

?random=true   -> True
?random=false -> False

However, Pydantic's non-strict boolean parsing also accepts other representations:

?random=1      -> True
?random=0 -> False

This makes the actual API validation more permissive than the generated OpenAPI schema.

How it should be?

Maybe it should be possible to use strict boolean validation for query parameters while still accepting their valid HTTP/OpenAPI representation?

Used versions

0.14.0

OS information

Not important for this case

(please, do not take this issue before the 1st of September)


#bug #good_first_issue #help_wanted #openapi #opensource_september #django_modern_rest
sent via relator
More from @opensource_findings_python
  1. Sep 25, 2026🚀 New issue to wemake-services/wemake-python-styleguide by @sobolevn 📝 Incorrect Jones c…
  2. Sep 25, 2026🚀 New issue to wemake-services/django-modern-rest by @sobolevn 📝 `_validate_throttling`…
  3. Sep 24, 2026🚀 New issue to wemake-services/django-modern-rest by @sobolevn 📝 Flaky `test_empty_valid…
  4. Sep 24, 2026🚀 New issue to wemake-services/django-modern-rest by @sobolevn 📝 `CookieJWT[A]syncAuth`…
  5. Sep 23, 2026🚀 New issue to ag2ai/faststream by @IvanKirpichnikov 📝 Feature: Implementation of the `A…
  6. Sep 22, 2026🚀 New issue to faststream-community/zMQTT by @borisalekseev 📝 Mark flaky Artemis test xf…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →