Skip to content

[Bug]: UnboundLocalError: local variable 'value' referenced before assignment #696

@andersk

Description

@andersk

Actual Behavior

Traceback (most recent call last):
  File "/home/anders/python/openapi-core/test.py", line 38, in <module>
    validate_request(request, spec=spec)
  File "/home/anders/python/openapi-core/openapi_core/shortcuts.py", line 321, in validate_request
    validate_apicall_request(
  File "/home/anders/python/openapi-core/openapi_core/shortcuts.py", line 396, in validate_apicall_request
    return v.validate(request)
  File "/home/anders/python/openapi-core/openapi_core/validation/request/validators.py", line 278, in validate
    for err in self.iter_errors(request):
  File "/home/anders/python/openapi-core/openapi_core/validation/request/validators.py", line 341, in iter_errors
    yield from self._iter_errors(request, operation, path)
  File "/home/anders/python/openapi-core/openapi_core/validation/request/validators.py", line 114, in _iter_errors
    self._get_body(request.body, request.mimetype, operation)
  File "/home/anders/python/openapi-core/openapi_core/validation/decorators.py", line 31, in wrapper
    return f(*args, **kwds)
  File "/home/anders/python/openapi-core/openapi_core/validation/request/validators.py", line 260, in _get_body
    value, _ = self._get_content_and_schema(raw_body, content, mimetype)
  File "/home/anders/python/openapi-core/openapi_core/validation/validators.py", line 244, in _get_content_and_schema
    casted, schema = self._get_content_schema_value_and_schema(
  File "/home/anders/python/openapi-core/openapi_core/validation/validators.py", line 230, in _get_content_schema_value_and_schema
    deserialised = self._deserialise_media_type(
  File "/home/anders/python/openapi-core/openapi_core/validation/validators.py", line 118, in _deserialise_media_type
    return deserializer.deserialize(value)
  File "/home/anders/python/openapi-core/openapi_core/deserializing/media_types/deserializers.py", line 90, in deserialize
    return self.decode(deserialized)
  File "/home/anders/python/openapi-core/openapi_core/deserializing/media_types/deserializers.py", line 111, in decode
    properties[prop_name] = self.decode_property(
  File "/home/anders/python/openapi-core/openapi_core/deserializing/media_types/deserializers.py", line 138, in decode_property
    return self.decode_property_content_type(
  File "/home/anders/python/openapi-core/openapi_core/deserializing/media_types/deserializers.py", line 179, in decode_property_content_type
    return list(map(prop_deserializer.deserialize, value))
UnboundLocalError: local variable 'value' referenced before assignment

Expected Behavior

No error.

Steps to Reproduce

from openapi_core import Spec, validate_request
from openapi_core.testing import MockRequest

spec = Spec.from_dict(
    {
        "openapi": "3.1.0",
        "info": {"version": "0", "title": "test"},
        "paths": {
            "/test": {
                "post": {
                    "requestBody": {
                        "content": {
                            "application/x-www-form-urlencoded": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "foo": {"type": "array", "items": {"type": "string"}}
                                    },
                                },
                                "encoding": {"foo": {"contentType": "application/json"}},
                            }
                        }
                    },
                    "responses": {"200": {"description": "OK"}},
                }
            }
        },
    }
)

request = MockRequest(
    "http://localhost",
    "post",
    "/test",
    data='foo=["a","b","c"]',
    mimetype="application/x-www-form-urlencoded",
)
validate_request(request, spec=spec)

OpenAPI Core Version

current Git (0838a84)

OpenAPI Core Integration

none

Affected Area(s)

No response

References

No response

Anything else we need to know?

No response

Would you like to implement a fix?

None

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bugIndicates an issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions