8000 JSON parsing from bytes fails in `allow_partial` mode when the final bytes are not a valid unicode point. · Issue #1633 · pydantic/pydantic-core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
JSON parsing from bytes fails in allow_partial mode when the final bytes are not a valid unicode point. #1633
Open
@dmontagu

Description

@dmontagu

I think when allowing partial JSON, and parsing from bytes, we shouldn't get errors if the trailing characters are not valid unicode.

Example demonstrating misbehavior:

from pydantic_core import SchemaValidator, core_schema

my_partial_string = '"abc€'  # works fine if you replace with = '"abc€d'
non_unicode_partial_string_bytes = my_partial_string.encode()[:-1]
SchemaValidator(core_schema.any_schema()).validate_json(non_unicode_partial_string_bytes, allow_partial='trailing-strings')
"""
pydantic_core._pydantic_core.ValidationError: 1 validation error for any
  Invalid JSON: invalid unicode code point at line 1 column 6 [type=json_invalid, input_value=b'"abc\xe2\x82', input_type=bytes]
    For further information visit https://errors.pydantic.dev/2.10/v/json_invalid
"""

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0