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

PydanticSerializationError missing validation error field name #1483

Open
ddennerline3 opened this issue Oct 12, 2024 · 5 comments
Open

PydanticSerializationError missing validation error field name #1483

ddennerline3 opened this issue Oct 12, 2024 · 5 comments
Assignees
Labels
good first issue Good for newcomers

Comments

@ddennerline3
Copy link

ddennerline3 commented Oct 12, 2024

I am getting quite a few of these Expected 'int' but got 'float' - serialized value may not be as expected warnings in the log files. Is there a way to callout the specific field name?

I looked at Rust's exception and error message, and I don't see any "add_variable_context" flag.

If not easily possible, would it be possible to add the field name that is triggering the warning to PydanticSerializationError please.

The object that is triggering the exception has large number of sub-objects and fields, so going through all the fields would be very time consuming.

# Internal imports

# External imports
from pydantic import BaseModel
from pydantic_core import PydanticSerializationError


# Own imports

class TestModelDump(BaseModel):
    int_value: int | None = None
    float_value: float | None = None


def test_mismatch():
    valu = TestModelDump(int_value=1, float_value=1.0)
    result = valu.model_dump_json()
    print(result)

    valu = TestModelDump(int_value=1.0, float_value=1.0)
    result = valu.model_dump_json(warnings="error")
    print(result)

    valu = TestModelDump(int_value=1.0, float_value=1)
    valu.int_value = 1.0
    valu.float_value = 1
    try:
        result = valu.model_dump_json(warnings="error")
    except PydanticSerializationError as e:
        print(e)
    else:
        print(result)
@davidhewitt
Copy link
Contributor

Seems like a reasonable request to me, I think this just needs some refactoring. cc @sydney-runkle

@sydney-runkle
Copy link
Member

Indeed, a good first issue if anyone wants to pick this up.

@joabreu
Copy link

joabreu commented Nov 11, 2024

I can pick this one up and contribute, can you please assign me along with @crdsteixeira? We can pair.

Thanks,
Jose

@crdsteixeira
Copy link

I'm up for it 😃

@crdsteixeira
Copy link

Hi @sydney-runkle , can you please assign us the issue? 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

5 participants