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
Some recursive models do not require update_forward_refs
and silently behave incorrectly
#1201
Comments
yes, very likely related to |
Looks like it fails in the same way. This test passes: from typing import List, Tuple
from pydantic import BaseModel
def test_parse_nested_tuple():
class NestedTuple(BaseModel):
x: Tuple[int, List["NestedTuple"]]
obj = NestedTuple.parse_obj({'x': ('1', [{'x': ('2', [{'x': ('3', [])}])}])})
assert obj.dict() == {'x': (1, [{'x': ('2', [{'x': ('3', [])}])}])}
# Note above: the 2 and 3 did not get parsed into ints !!
NestedTuple.update_forward_refs()
obj = NestedTuple.parse_obj({'x': ('1', [{'x': ('2', [{'x': ('3', [])}])}])})
assert obj.dict() == {'x': (1, [{'x': (2, [{'x': (3, [])}])}])} |
Looks like a problem of checking
Maybe we can move the checking into |
* fix: force need of `update_forward_refs` in recursive models closes #1201 * fix: lint issue (false positive) PyCQA/pyflakes#567 * chore: avoid if statement for coverage * fix linting Co-authored-by: Samuel Colvin <s@muelcolvin.com>
Bug
Output of
python -c "import pydantic.utils; print(pydantic.utils.version_info())"
:This test passes on master, but it should not:
Presumably we should either get an error at some point prior to the
NestedRootTuple.update_forward_refs()
call, or the two calls toobj.dict()
should generate the same output.I'm guessing this is related to the field being
Optional
, but I'm not sure. I discovered it while working on #1200 .The text was updated successfully, but these errors were encountered: