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

Optimistically close string values in from_json if allow_partial is set to true #100

Closed
mwildehahn opened this issue Apr 4, 2024 · 4 comments
Assignees
Labels
enhancement New feature or request

Comments

@mwildehahn
Copy link

Right now if you're trying to parse a partial object, pydantic won't return the key until the string value is complete:

In [4]: pydantic_core.from_json('{"test": "this', allow_partial=True)
Out[4]: {}

I'd expect this to result in:

In [5]: pydantic_core.from_json('{"test": "this', allow_partial=True)
Out[5]: {'test': 'this'}

similarly to how objects and lists are optimistically closed during partial rendering.

@adriangb
Copy link
Member

adriangb commented Apr 4, 2024

I'm not sure I agree. Lists are heterogenous: if a full list is valid, half a list should be as well. Objects are not. Cutting an object in half does not guarantee you can validate it.

@mwildehahn
Copy link
Author

Hm, I'm specifically talking about closing strings. I mentioned objects because they are optimistically closed already:

In [4]: pydantic_core.from_json('{"test": "this", "something": {', allow_partial=True)
Out[4]: {'test': 'this', 'something': {}}

If a value of a key is a string, it will always be a string, optimistically closing that string just lets us serve a partial string faster.

@adriangb
Copy link
Member

adriangb commented Apr 4, 2024

Ah sorry, misunderstood. That makes sense.

@samuelcolvin samuelcolvin added the enhancement New feature or request label May 21, 2024
@samuelcolvin samuelcolvin transferred this issue from pydantic/pydantic-core May 21, 2024
@samuelcolvin
Copy link
Member

Just noticed this is a duplicate of #82.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants