Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON parsing from bytes fails in allow_partial mode when the final bytes are not a valid unicode point. #1633

Open
dmontagu opened this issue Feb 12, 2025 · 0 comments

Comments

@dmontagu
Copy link
Collaborator

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
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant