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

Strict bug :( with config vs runtime flag #1247

Open
sydney-runkle opened this issue Mar 26, 2024 · 0 comments
Open

Strict bug :( with config vs runtime flag #1247

sydney-runkle opened this issue Mar 26, 2024 · 0 comments
Assignees

Comments

@sydney-runkle
Copy link
Member

@pytest.mark.xfail(
    reason='strict=True in model_validate_json does not overwrite strict=False given in ConfigDict'
    'See issue: https://github.com/pydantic/pydantic/issues/8930'
)
def test_model_validate_list_strict() -> None:
    # FIXME: This change must be implemented in pydantic-core. The argument strict=True
    # in model_validate_json method is not overwriting the one set with ConfigDict(strict=False)
    # for sequence like types. See: https://github.com/pydantic/pydantic/issues/8930

    class LaxModel(BaseModel):
        x: List[str]
        model_config = ConfigDict(strict=False)

    assert LaxModel.model_validate_json(json.dumps({'x': ('a', 'b', 'c')}), strict=None) == LaxModel(x=('a', 'b', 'c'))
    assert LaxModel.model_validate_json(json.dumps({'x': ('a', 'b', 'c')}), strict=False) == LaxModel(x=('a', 'b', 'c'))
    with pytest.raises(ValidationError) as exc_info:
        LaxModel.model_validate_json(json.dumps({'x': ('a', 'b', 'c')}), strict=True)
    assert exc_info.value.errors(include_url=False) == [
        {'type': 'list_type', 'loc': ('x',), 'msg': 'Input should be a valid list', 'input': ('a', 'b', 'c')}
    ]

Revealed when investigating our abundance of sequence validator issues :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants