From 3eb3b20157bdadb48645fc2ba4cd4e4ac2c0fb98 Mon Sep 17 00:00:00 2001 From: Krisque <63082743+chrisemke@users.noreply.github.com> Date: Thu, 26 Sep 2024 09:22:21 -0300 Subject: [PATCH] fix: pydantic ^2.9.0 needs 2 extra fields on to_argument (#3632) * fix: pydantic ^2.9.0 needs 2 extra fields on to_argument * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * docs: add RELEASE.md file * Update .alexrc to allow crash * Update RELEASE.md --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Patrick Arminio --- .alexrc | 3 ++- RELEASE.md | 3 +++ strawberry/ext/mypy_plugin.py | 9 ++++++++- 3 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 RELEASE.md diff --git a/.alexrc b/.alexrc index db2914316a..587b769682 100644 --- a/.alexrc +++ b/.alexrc @@ -11,6 +11,7 @@ "execution", "special", "primitive", - "invalid" + "invalid", + "crash", ] } diff --git a/RELEASE.md b/RELEASE.md new file mode 100644 index 0000000000..9e2deb1dac --- /dev/null +++ b/RELEASE.md @@ -0,0 +1,3 @@ +Release type: patch + +This releases adds support for Pydantic 2.9.0's Mypy plugin diff --git a/strawberry/ext/mypy_plugin.py b/strawberry/ext/mypy_plugin.py index 5d5c3d08ef..77a8a406f0 100644 --- a/strawberry/ext/mypy_plugin.py +++ b/strawberry/ext/mypy_plugin.py @@ -481,7 +481,14 @@ def strawberry_pydantic_class_callback(ctx: ClassDefContext) -> None: # Based on pydantic's default value # https://github.com/pydantic/pydantic/pull/9606/files#diff-469037bbe55bbf9aa359480a16040d368c676adad736e133fb07e5e20d6ac523R1066 extra["force_typevars_invariant"] = False - + if PYDANTIC_VERSION >= (2, 9, 0): + extra["model_strict"] = model_type.type.metadata[ + PYDANTIC_METADATA_KEY + ]["config"].get("strict", False) + extra["is_root_model_root"] = any( + "pydantic.root_model.RootModel" in base.fullname + for base in model_type.type.mro[:-1] + ) add_method( ctx, "to_pydantic",