Skip to content

Commit 300eb29

Browse files
authored
Merge pull request #589 from python-openapi/fix/validate-request-response-deprecation-warning-fix
validate_request and validate_response return value deprecation fix
2 parents 35872a9 + cec771c commit 300eb29

File tree

5 files changed

+217
-241
lines changed

5 files changed

+217
-241
lines changed

openapi_core/shortcuts.py

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
from typing import Optional
66
from typing import Union
77

8+
from lazy_object_proxy import Proxy
9+
810
from openapi_core.exceptions import SpecError
911
from openapi_core.finders import SpecClasses
1012
from openapi_core.finders import SpecFinder
@@ -317,19 +319,24 @@ def validate_request(
317319
if cls is None or issubclass(
318320
cls, (RequestUnmarshaller, WebhookRequestUnmarshaller)
319321
):
320-
warnings.warn(
321-
"validate_request is deprecated for unmarshalling data "
322-
"and it will not return any result in the future. "
323-
"Use unmarshal_request function instead.",
324-
DeprecationWarning,
325-
)
326-
return unmarshal_request(
322+
result = unmarshal_request(
327323
request,
328324
spec=spec,
329325
base_url=base_url,
330326
cls=cls,
331327
**validator_kwargs,
332328
)
329+
330+
def return_result() -> RequestUnmarshalResult:
331+
warnings.warn(
332+
"validate_request is deprecated for unmarshalling data "
333+
"and it will not return any result in the future. "
334+
"Use unmarshal_request function instead.",
335+
DeprecationWarning,
336+
)
337+
return result
338+
339+
return Proxy(return_result) # type: ignore
333340
if isinstance(request, WebhookRequest):
334341
if cls is None or issubclass(cls, WebhookRequestValidator):
335342
validate_webhook_request(
@@ -400,20 +407,25 @@ def validate_response(
400407
if cls is None or issubclass(
401408
cls, (ResponseUnmarshaller, WebhookResponseUnmarshaller)
402409
):
403-
warnings.warn(
404-
"validate_response is deprecated for unmarshalling data "
405-
"and it will not return any result in the future. "
406-
"Use unmarshal_response function instead.",
407-
DeprecationWarning,
408-
)
409-
return unmarshal_response(
410+
result = unmarshal_response(
410411
request,
411412
response,
412413
spec=spec,
413414
base_url=base_url,
414415
cls=cls,
415416
**validator_kwargs,
416417
)
418+
419+
def return_result() -> ResponseUnmarshalResult:
420+
warnings.warn(
421+
"validate_response is deprecated for unmarshalling data "
422+
"and it will not return any result in the future. "
423+
"Use unmarshal_response function instead.",
424+
DeprecationWarning,
425+
)
426+
return result
427+
428+
return Proxy(return_result) # type: ignore
417429
if isinstance(request, WebhookRequest):
418430
if cls is None or issubclass(cls, WebhookResponseValidator):
419431
validate_webhook_response(

poetry.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ module = [
2727
]
2828
ignore_missing_imports = true
2929

30+
[[tool.mypy.overrides]]
31+
module = "lazy_object_proxy.*"
32+
ignore_missing_imports = true
33+
3034
[tool.poetry]
3135
name = "openapi-core"
3236
version = "0.17.1"
@@ -74,6 +78,7 @@ backports-cached-property = {version = "^1.0.2", python = "<3.8" }
7478
asgiref = "^3.6.0"
7579
jsonschema = "^4.17.3"
7680
multidict = {version = "^6.0.4", optional = true}
81+
lazy-object-proxy = "^1.7.1"
7782

7883
[tool.poetry.extras]
7984
django = ["django"]

0 commit comments

Comments
 (0)