failed WRONG_FIX UNSUBMITTED wrong_fix_unsubmitted(timeout) · 21 tool calls · 0 s · fastapi/fastapi
🐛 Fix internal Pydantic v1 compatibility (warnings) for Python 3.14 and Pydantic 2.12.1 The Python 3.14 tests started failing with the Pydantic v.2.12.1 release, because of the combination of https://github.com/fastapi/fastapi/pull/14168 and https://github.com/pydantic/pydantic/pull/12367. Basically we were importing Pydantic `v1` functionality even when the user had (only) Pydantic v2 installed. This was done in https://github.com/fastapi/fastapi/pull/14168 to support more easy migration from v1 to v2 by allowing mixing versions within the same app. Here, we prevent importing any `v1` functionality by creating dummy classes for Python 3.14 / Pydantic 2.12.0 onwards, which [drops support](https://github.com/pydantic/pydantic/releases/tag/v2.12.0) for `v1` and emits a [warning](https://github.com/pydantic/pydantic/pull/12367) when importing `v1` functionality. ### TODO - [x] fix coverage - [ ] check warning is still shown to users at some point, and not just swallowed by this code.
| # | Tool | Arguments | Result |
|---|---|---|---|
| 1 | run_command | {
"command": "grep -rn \"pydantic.v1\" fastapi/_compat | head -20"
} | {"status": "ok", "stdout": "fastapi/_compat/__init__.py:36:from .shared import annotation_is_pydantic_v1 as annotation_is_pydantic_v1\nfastapi/_compat/shared.pyfull{"status": "ok", "stdout": "fastapi/_compat/__init__.py:36:from .shared import annotation_is_pydantic_v1 as annotation_is_pydantic_v1\nfastapi/_compat/shared.py:197:def annotation_is_pydantic_v1(annotation: Any) -> bool:\nfastapi/_compat/shared.py:207: if annotation_is_pydantic_v1(sub_annotation):\nfastapi/_compat/v1.py:72: from pydantic.v1 import BaseConfig as BaseConfig # type: ignore[assignment]\nfastapi/_compat/v1.py:73: from pydantic.v1 import BaseModel as BaseModel # type: ignore[assignment]\nfastapi/_compat/v1.py:74: from pydantic.v1 import ( # type: ignore[assignment]\nfastapi/_compat/v1.py:77: from pydantic.v1 import create_model as create_model # type: ignore[no-redef]\nfastapi/_compat/v1.py:78: from pydantic.v1.class_validators import Validator as Validator\nfastapi/_compat/v1.py:79: from pydantic.v1.color import Color as Color # type: ignore[assignment]\nfastapi/_compat/v1.py:80: from pydantic.v1.error_wrappers import ErrorWrapper as ErrorWrapper\nfastapi/_compat/v1.py:81: from pydantic.v1.errors import MissingError\nfastapi/_compat/v1.py:82: from pydantic.v1.fields import (\nfastapi/_compat/v1.py:91: from pydantic.v1.fields import FieldInfo as FieldInfo # type: ignore[assignment]\nfastapi/_compat/v1.py:92: from pydantic.v1.fields import ModelField as ModelField\nfastapi/_compat/v1.py:93: from pydantic.v1.fields import Undefined as Undefined\nfastapi/_compat/v1.py:94: from pydantic.v1.fields import UndefinedType as UndefinedType\nfastapi/_compat/v1.py:95: from pydantic.v1.networks import AnyUrl as AnyUrl\nfastapi/_compat/v1.py:96: from pydantic.v1.networks import ( # type: ignore[assignment]\nfastapi/_compat/v1.py:99: from pydantic.v1.schema import TypeModelSet as TypeModelSet\nfastapi/_compat/v1.py:100: from pydantic.v1.schema import (\n", "exit_code": 0} |
| 2 | read_file | {
"filepath": "fastapi/_compat/v1.py"
} | {"status": "ok", "filepath": "fastapi/_compat/v1.py", "content": "from copy import copy\nfrom dataclasses import dataclass, is_dataclass\nfrom enum import Enum\full{"status": "ok", "filepath": "fastapi/_compat/v1.py", "content": "from copy import copy\nfrom dataclasses import dataclass, is_dataclass\nfrom enum import Enum\nfrom typing import (\n Any,\n Callable,\n Dict,\n List,\n Sequence,\n Set,\n Tuple,\n Type,\n Union,\n)\n\nfrom fastapi._compat import shared\nfrom fastapi.openapi.constants import REF_PREFIX as REF_PREFIX\nfrom fastapi.types import ModelNameMap\nfrom pydantic.version import VERSION as PYDANTIC_VERSION\nfrom typing_extensions import Literal\n\nPYDANTIC_VERSION_MINOR_TUPLE = tuple(int(x) for x in PYDANTIC_VERSION.split(\".\")[:2])\nPYDANTIC_V2 = PYDANTIC_VERSION_MINOR_TUPLE[0] == 2\n# Keeping old \"Required\" functionality from Pydantic V1, without\n# shadowing typing.Required.\nRequiredParam: Any = Ellipsis\n\nif not PYDANTIC_V2:\n from pydantic import BaseConfig as BaseConfig\n from pydantic import BaseModel as BaseModel\n from pydantic import ValidationError as ValidationError\n from pydantic import create_model as create_model\n from pydantic.class_validators import Validator as Validator\n from pydantic.color import Color as Color\n from pydantic.error_wrappers import ErrorWrapper as ErrorWrapper\n from pydantic.errors import MissingError\n from pydantic.fields import ( # type: ignore[attr-defined]\n SHAPE_FROZENSET,\n SHAPE_LIST,\n SHAPE_SEQUENCE,\n SHAPE_SET,\n SHAPE_SINGLETON,\n SHAPE_TUPLE,\n SHAPE_TUPLE_ELLIPSIS,\n )\n from pydantic.fields import FieldInfo as FieldInfo\n from pydantic.fields import ModelField as ModelField # type: ignore[attr-defined]\n from pydantic.fields import Undefined as Undefined # type: ignore[attr-defined]\n from pydantic.fields import ( # type: ignore[attr-defined]\n UndefinedType as UndefinedType,\n )\n from pydantic.networks import AnyUrl as AnyUrl\n from pydantic.networks import NameEmail as NameEmail\n from pydantic.schema import |
| 3 | run_command | {
"command": "python3 -c \"import pydantic; print(pydantic.VERSION)\""
} | {"status": "ok", "stdout": "2.13.5\n", "exit_code": 0}full{"status": "ok", "stdout": "2.13.5\n", "exit_code": 0} |
| 4 | read_file | {
"filepath": "fastapi/_compat/v1.py",
"start_line": 1,
"end_line": 30
} | {"status": "ok", "filepath": "fastapi/_compat/v1.py", "content": "from copy import copy\nfrom dataclasses import dataclass, is_dataclass\nfrom enum import Enum\full{"status": "ok", "filepath": "fastapi/_compat/v1.py", "content": "from copy import copy\nfrom dataclasses import dataclass, is_dataclass\nfrom enum import Enum\nfrom typing import (\n Any,\n Callable,\n Dict,\n List,\n Sequence,\n Set,\n Tuple,\n Type,\n Union,\n)\n\nfrom fastapi._compat import shared\nfrom fastapi.openapi.constants import REF_PREFIX as REF_PREFIX\nfrom fastapi.types import ModelNameMap\nfrom pydantic.version import VERSION as PYDANTIC_VERSION\nfrom typing_extensions import Literal\n\nPYDANTIC_VERSION_MINOR_TUPLE = tuple(int(x) for x in PYDANTIC_VERSION.split(\".\")[:2])\nPYDANTIC_V2 = PYDANTIC_VERSION_MINOR_TUPLE[0] == 2\n# Keeping old \"Required\" functionality from Pydantic V1, without\n# shadowing typing.Required.\nRequiredParam: Any = Ellipsis\n\nif not PYDANTIC_V2:\n from pydantic import BaseConfig as BaseConfig\n from pydantic import BaseModel as BaseModel\n", "start_line": 1, "end_line": 30, "total_lines": 334, "is_truncated": false} |
| 5 | edit_file | {
"filepath": "fastapi/_compat/v1.py",
"new_string": "PYDANTIC_VERSION_MINOR_TUPLE = tuple(int(x) for x in PYDANTIC_VERSION.split(\\\".\\\")[:2])\\nPYDANTIC_V2 = PYDANTIC_VERSION_MINOR_TUPLE[0] == 2\\n# Pydantic v2.12.0+ drops support for v1 and emits a warning when importing it.\\n# We avoid importing pydantic.v1 in these cases to prevent the warning.\\nPYDANTIC_V1_SUPPORTED = not (PYDANTIC_V2 and PYDANTIC_VERSION_MINOR_TUPLE[1] >= 12)\\n# Keeping old \\\"Required\\\" functionality from Pydantic V1, without\\n# shadowing typing.Required.\\nRequiredParam: Any = Ellipsis\\n\\nif not PYDANTIC_V2:",
"old_string": "PYDANTIC_VERSION_MINOR_TUPLE = tuple(int(x) for x in PYDANTIC_VERSION.split(\\\".\\\")[:2])\\nPYDANTIC_V2 = PYDANTIC_VERSION_MINOR_TUPLE[0] == 2\\n# Keeping old \\\"Required\\\" functionality from Pydantic V1, without\\n# shadowing typing.Required.\\nRequiredParam: Any = Ellipsis\\n\\nif not PYDANTIC_V2:"
} | {"status": "error", "error_type": "FileEditError", "error_message": "old_string not found in file (tried exact, flexible and regex matching)"}full{"status": "error", "error_type": "FileEditError", "error_message": "old_string not found in file (tried exact, flexible and regex matching)"} |
| 6 | read_file | {
"end_line": 30,
"filepath": "fastapi/_compat/v1.py",
"start_line": 1
} | {"status": "ok", "filepath": "fastapi/_compat/v1.py", "content": "from copy import copy\nfrom dataclasses import dataclass, is_dataclass\nfrom enum import Enum\full{"status": "ok", "filepath": "fastapi/_compat/v1.py", "content": "from copy import copy\nfrom dataclasses import dataclass, is_dataclass\nfrom enum import Enum\nfrom typing import (\n Any,\n Callable,\n Dict,\n List,\n Sequence,\n Set,\n Tuple,\n Type,\n Union,\n)\n\nfrom fastapi._compat import shared\nfrom fastapi.openapi.constants import REF_PREFIX as REF_PREFIX\nfrom fastapi.types import ModelNameMap\nfrom pydantic.version import VERSION as PYDANTIC_VERSION\nfrom typing_extensions import Literal\n\nPYDANTIC_VERSION_MINOR_TUPLE = tuple(int(x) for x in PYDANTIC_VERSION.split(\".\")[:2])\nPYDANTIC_V2 = PYDANTIC_VERSION_MINOR_TUPLE[0] == 2\n# Keeping old \"Required\" functionality from Pydantic V1, without\n# shadowing typing.Required.\nRequiredParam: Any = Ellipsis\n\nif not PYDANTIC_V2:\n from pydantic import BaseConfig as BaseConfig\n from pydantic import BaseModel as BaseModel\n", "start_line": 1, "end_line": 30, "total_lines": 334, "is_truncated": false} |
| 7 | edit_file | {
"filepath": "fastapi/_compat/v1.py",
"new_string": "PYDANTIC_VERSION_MINOR_TUPLE = tuple(int(x) for x in PYDANTIC_VERSION.split(\\\".\\\")[:2])\\nPYDANTIC_V2 = PYDANTIC_VERSION_MINOR_TUPLE[0] == 2\\n# Pydantic v2.12.0+ drops support for v1 and emits a warning when importing it.\\n# We avoid importing pydantic.v1 in these cases to prevent the warning.\\nPYDANTIC_V1_SUPPORTED = not (PYDANTIC_V2 and PYDANTIC_VERSION_MINOR_TUPLE[1] >= 12)\\n# Keeping old \\\"Required\\\" functionality from Pydantic V1, without\\n# shadowing typing.Required.\\nRequiredParam: Any = Ellipsis\\n\\nif not PYDANTIC_V2:",
"old_string": "PYDANTIC_VERSION_MINOR_TUPLE = tuple(int(x) for x in PYDANTIC_VERSION.split(\\\".\\\")[:2])\\nPYDANTIC_V2 = PYDANTIC_VERSION_MINOR_TUPLE[0] == 2\\n# Keeping old \\\"Required\\\" functionality from Pydantic V1, without\\n# shadowing typing.Required.\\nRequiredParam: Any = Ellipsis\\n\\nif not PYDANTIC_V2:"
} | {"status": "error", "error_type": "FileEditError", "error_message": "old_string not found in file (tried exact, flexible and regex matching)"}full{"status": "error", "error_type": "FileEditError", "error_message": "old_string not found in file (tried exact, flexible and regex matching)"} |
| 8 | read_file | {
"end_line": 25,
"filepath": "fastapi/_compat/v1.py",
"start_line": 15
} | {"status": "ok", "filepath": "fastapi/_compat/v1.py", "content": "\nfrom fastapi._compat import shared\nfrom fastapi.openapi.constants import REF_PREFIX as REF_full{"status": "ok", "filepath": "fastapi/_compat/v1.py", "content": "\nfrom fastapi._compat import shared\nfrom fastapi.openapi.constants import REF_PREFIX as REF_PREFIX\nfrom fastapi.types import ModelNameMap\nfrom pydantic.version import VERSION as PYDANTIC_VERSION\nfrom typing_extensions import Literal\n\nPYDANTIC_VERSION_MINOR_TUPLE = tuple(int(x) for x in PYDANTIC_VERSION.split(\".\")[:2])\nPYDANTIC_V2 = PYDANTIC_VERSION_MINOR_TUPLE[0] == 2\n# Keeping old \"Required\" functionality from Pydantic V1, without\n# shadowing typing.Required.\n", "start_line": 15, "end_line": 25, "total_lines": 334, "is_truncated": false} |
| 9 | edit_file | {
"filepath": "fastapi/_compat/v1.py",
"new_string": "PYDANTIC_VERSION_MINOR_TUPLE = tuple(int(x) for x in PYDANTIC_VERSION.split(\\\".\\\")[:2])\\nPYDANTIC_V2 = PYDANTIC_VERSION_MINOR_TUPLE[0] == 2\\n# Pydantic v2.12.0+ drops support for v1 and emits a warning when importing it.\\n# We avoid importing pydantic.v1 in these cases to prevent the warning.\\nPYDANTIC_V1_SUPPORTED = not (PYDANTIC_V2 and PYDANTIC_VERSION_MINOR_TUPLE[1] >= 12)\\n# Keeping old \\\"Required\\\" functionality from Pydantic V1, without\\n# shadowing typing.Required.",
"old_string": "PYDANTIC_VERSION_MINOR_TUPLE = tuple(int(x) for x in PYDANTIC_VERSION.split(\\\".\\\")[:2])\\nPYDANTIC_V2 = PYDANTIC_VERSION_MINOR_TUPLE[0] == 2\\n# Keeping old \\\"Required\\\" functionality from Pydantic V1, without\\n# shadowing typing.Required."
} | {"status": "error", "error_type": "FileEditError", "error_message": "old_string not found in file (tried exact, flexible and regex matching)"}full{"status": "error", "error_type": "FileEditError", "error_message": "old_string not found in file (tried exact, flexible and regex matching)"} |
| 10 | read_file | {
"end_line": 30,
"filepath": "fastapi/_compat/v1.py",
"start_line": 1
} | {"status": "ok", "filepath": "fastapi/_compat/v1.py", "content": "from copy import copy\nfrom dataclasses import dataclass, is_dataclass\nfrom enum import Enum\full{"status": "ok", "filepath": "fastapi/_compat/v1.py", "content": "from copy import copy\nfrom dataclasses import dataclass, is_dataclass\nfrom enum import Enum\nfrom typing import (\n Any,\n Callable,\n Dict,\n List,\n Sequence,\n Set,\n Tuple,\n Type,\n Union,\n)\n\nfrom fastapi._compat import shared\nfrom fastapi.openapi.constants import REF_PREFIX as REF_PREFIX\nfrom fastapi.types import ModelNameMap\nfrom pydantic.version import VERSION as PYDANTIC_VERSION\nfrom typing_extensions import Literal\n\nPYDANTIC_VERSION_MINOR_TUPLE = tuple(int(x) for x in PYDANTIC_VERSION.split(\".\")[:2])\nPYDANTIC_V2 = PYDANTIC_VERSION_MINOR_TUPLE[0] == 2\n# Keeping old \"Required\" functionality from Pydantic V1, without\n# shadowing typing.Required.\nRequiredParam: Any = Ellipsis\n\nif not PYDANTIC_V2:\n from pydantic import BaseConfig as BaseConfig\n from pydantic import BaseModel as BaseModel\n", "start_line": 1, "end_line": 30, "total_lines": 334, "is_truncated": false} |
| 11 | edit_file | {
"filepath": "fastapi/_compat/v1.py",
"new_string": "PYDANTIC_VERSION_MINOR_TUPLE = tuple(int(x) for x in PYDANTIC_VERSION.split(\\\".\\\")[:2])\\nPYDANTIC_V2 = PYDANTIC_VERSION_MINOR_TUPLE[0] == 2\\n# Pydantic v2.12.0+ drops support for v1 and emits a warning when importing it.\\n# We avoid importing pydantic.v1 in these cases to prevent the warning.\\nPYDANTIC_V1_SUPPORTED = not (PYDANTIC_V2 and PYDANTIC_VERSION_MINOR_TUPLE[1] >= 12)\\n# Keeping old \\\"Required\\\" functionality from Pydantic V1, without\\n# shadowing typing.Required.",
"old_string": "PYDANTIC_VERSION_MINOR_TUPLE = tuple(int(x) for x in PYDANTIC_VERSION.split(\\\".\\\")[:2])\\nPYDANTIC_V2 = PYDANTIC_VERSION_MINOR_TUPLE[0] == 2\\n# Keeping old \\\"Required\\\" functionality from Pydantic V1, without\\n# shadowing typing.Required."
} | {"status": "error", "error_type": "FileEditError", "error_message": "old_string not found in file (tried exact, flexible and regex matching)"}full{"status": "error", "error_type": "FileEditError", "error_message": "old_string not found in file (tried exact, flexible and regex matching)"} |
| 12 | run_command | {
"command": "cat -A fastapi/_compat/v1.py | head -30"
} | {"status": "ok", "stdout": "from copy import copy$\nfrom dataclasses import dataclass, is_dataclass$\nfrom enum import Enum$\nfrom typing import ($\n Any,$\n Cafull{"status": "ok", "stdout": "from copy import copy$\nfrom dataclasses import dataclass, is_dataclass$\nfrom enum import Enum$\nfrom typing import ($\n Any,$\n Callable,$\n Dict,$\n List,$\n Sequence,$\n Set,$\n Tuple,$\n Type,$\n Union,$\n)$\n$\nfrom fastapi._compat import shared$\nfrom fastapi.openapi.constants import REF_PREFIX as REF_PREFIX$\nfrom fastapi.types import ModelNameMap$\nfrom pydantic.version import VERSION as PYDANTIC_VERSION$\nfrom typing_extensions import Literal$\n$\nPYDANTIC_VERSION_MINOR_TUPLE = tuple(int(x) for x in PYDANTIC_VERSION.split(\".\")[:2])$\nPYDANTIC_V2 = PYDANTIC_VERSION_MINOR_TUPLE[0] == 2$\n# Keeping old \"Required\" functionality from Pydantic V1, without$\n# shadowing typing.Required.$\nRequiredParam: Any = Ellipsis$\n$\nif not PYDANTIC_V2:$\n from pydantic import BaseConfig as BaseConfig$\n from pydantic import BaseModel as BaseModel$\n", "exit_code": 0} |
| 13 | edit_file | {
"filepath": "fastapi/_compat/v1.py",
"new_string": "PYDANTIC_VERSION_MINOR_TUPLE = tuple(int(x) for x in PYDANTIC_VERSION.split(\".\")[0:2])\nPYDANTIC_V2 = PYDANTIC_VERSION_MINOR_TUPLE[0] == 2\n# Pydantic v2.12.0+ drops support for v1 and emits a warning when importing it.\n# We avoid importing pydantic.v1 in these cases to prevent the warning.\nPYDANTIC_V1_SUPPORTED = not (PYDANTIC_V2 and PYDANTIC_VERSION_MINOR_TUPLE[1] >= 12)\n# Keeping old \"Required\" functionality from Pydantic V1, without\n# shadowing typing.Required.",
"old_string": "PYDANTIC_VERSION_MINOR_TUPLE = tuple(int(x) for x in PYDANTIC_VERSION.split(\".\")[0:2])\nPYDANTIC_V2 = PYDANTIC_VERSION_MINOR_TUPLE[0] == 2\n# Keeping old \"Required\" functionality from Pydantic V1, without\n# shadowing typing.Required."
} | {"status": "error", "error_type": "FileEditError", "error_message": "old_string not found in file (tried exact, flexible and regex matching)"}full{"status": "error", "error_type": "FileEditError", "error_message": "old_string not found in file (tried exact, flexible and regex matching)"} |
| 14 | edit_file | {
"filepath": "fastapi/_compat/v1.py",
"new_string": "PYDANTIC_VERSION_MINOR_TUPLE = tuple(int(x) for x in PYDANTIC_VERSION.split(\".\")[:2])\nPYDANTIC_V2 = PYDANTIC_VERSION_MINOR_TUPLE[0] == 2\n# Pydantic v2.12.0+ drops support for v1 and emits a warning when importing it.\n# We avoid importing pydantic.v1 in these cases to prevent the warning.\nPYDANTIC_V1_SUPPORTED = not (PYDANTIC_V2 and PYDANTIC_VERSION_MINOR_TUPLE[1] >= 12)\n# Keeping old \"Required\" functionality from Pydantic V1, without\n# shadowing typing.Required.",
"old_string": "PYDANTIC_VERSION_MINOR_TUPLE = tuple(int(x) for x in PYDANTIC_VERSION.split(\".\")[:2])\nPYDANTIC_V2 = PYDANTIC_VERSION_MINOR_TUPLE[0] == 2\n# Keeping old \"Required\" functionality from Pydantic V1, without\n# shadowing typing.Required."
} | {"status": "ok", "filepath": "fastapi/_compat/v1.py", "occurrences": 1, "strategy": "exact", "diff": "--- a/fastapi/_compat/v1.py\n+++ b/fastapi/_compat/v1.py\nfull{"status": "ok", "filepath": "fastapi/_compat/v1.py", "occurrences": 1, "strategy": "exact", "diff": "--- a/fastapi/_compat/v1.py\n+++ b/fastapi/_compat/v1.py\n@@ -21,6 +21,9 @@\n \n PYDANTIC_VERSION_MINOR_TUPLE = tuple(int(x) for x in PYDANTIC_VERSION.split(\".\")[:2])\n PYDANTIC_V2 = PYDANTIC_VERSION_MINOR_TUPLE[0] == 2\n+# Pydantic v2.12.0+ drops support for v1 and emits a warning when importing it.\n+# We avoid importing pydantic.v1 in these cases to prevent the warning.\n+PYDANTIC_V1_SUPPORTED = not (PYDANTIC_V2 and PYDANTIC_VERSION_MINOR_TUPLE[1] >= 12)\n # Keeping old \"Required\" functionality from Pydantic V1, without\n # shadowing typing.Required.\n RequiredParam: Any = Ellipsis\n", "is_truncated": false} |
| 15 | read_file | {
"end_line": 150,
"filepath": "fastapi/_compat/v1.py",
"start_line": 31
} | {"status": "ok", "filepath": "fastapi/_compat/v1.py", "content": "if not PYDANTIC_V2:\n from pydantic import BaseConfig as BaseConfig\n from pydantic import Basfull{"status": "ok", "filepath": "fastapi/_compat/v1.py", "content": "if not PYDANTIC_V2:\n from pydantic import BaseConfig as BaseConfig\n from pydantic import BaseModel as BaseModel\n from pydantic import ValidationError as ValidationError\n from pydantic import create_model as create_model\n from pydantic.class_validators import Validator as Validator\n from pydantic.color import Color as Color\n from pydantic.error_wrappers import ErrorWrapper as ErrorWrapper\n from pydantic.errors import MissingError\n from pydantic.fields import ( # type: ignore[attr-defined]\n SHAPE_FROZENSET,\n SHAPE_LIST,\n SHAPE_SEQUENCE,\n SHAPE_SET,\n SHAPE_SINGLETON,\n SHAPE_TUPLE,\n SHAPE_TUPLE_ELLIPSIS,\n )\n from pydantic.fields import FieldInfo as FieldInfo\n from pydantic.fields import ModelField as ModelField # type: ignore[attr-defined]\n from pydantic.fields import Undefined as Undefined # type: ignore[attr-defined]\n from pydantic.fields import ( # type: ignore[attr-defined]\n UndefinedType as UndefinedType,\n )\n from pydantic.networks import AnyUrl as AnyUrl\n from pydantic.networks import NameEmail as NameEmail\n from pydantic.schema import TypeModelSet as TypeModelSet\n from pydantic.schema import (\n field_schema,\n get_flat_models_from_fields,\n model_process_schema,\n )\n from pydantic.schema import (\n get_annotation_from_field_info as get_annotation_from_field_info,\n )\n from pydantic.schema import get_flat_models_from_field as get_flat_models_from_field\n from pydantic.schema import get_model_name_map as get_model_name_map\n from pydantic.types import SecretBytes as SecretBytes\n from pydantic.types import SecretStr as SecretStr\n from pydantic.typing import evaluate_forwardref as evaluate_forwardref\n from pydantic.utils import lenient_issubclass as lenient_issubclass\n\n\nelse:\n from pydantic.v1 |
| 16 | edit_file | {
"filepath": "fastapi/_compat/v1.py",
"new_string": "else:\\n if PYDANTIC_V1_SUPPORTED:\\n from pydantic.v1 import BaseConfig as BaseConfig # type: ignore[assignment]\\n from pydantic.v1 import BaseModel as BaseModel # type: ignore[assignment]\\n from pydantic.v1 import ( # type: ignore[assignment]\\n ValidationError as ValidationError,\\n )\\n from pydantic.v1 import create_model as create_model # type: ignore[no-redef]\\n from pydantic.v1.class_validators import Validator as Validator\\n from pydantic.v1.color import Color as Color # type: ignore[assignment]\\n from pydantic.v1.error_wrappers import ErrorWrapper as ErrorWrapper\\n from pydantic.v1.errors import MissingError\\n from pydantic.v1.fields import (\\n SHAPE_FROZENSET,\\n SHAPE_LIST,\\n SHAPE_SEQUENCE,\\n SHAPE_SET,\\n SHAPE_SINGLETON,\\n SHAPE_TUPLE,\\n SHAPE_TUPLE_ELLIPSIS,\\n )\\n from pydantic.v1.fields import FieldInfo as FieldInfo # type: ignore[assignment]\\n from pydantic.v1.fields import ModelField as ModelField\\n from pydantic.v1.fields import Undefined as Undefined\\n from pydantic.v1.fields import UndefinedType as UndefinedType\\n from pydantic.v1.networks import AnyUrl as AnyUrl\\n from pydantic.v1.networks import ( # type: ignore[assignment]\\n NameEmail as NameEmail,\\n )\\n from pydantic.v1.schema import TypeModelSet as TypeModelSet\\n from pydantic.v1.schema import (\\n field_schema,\\n get_flat_models_from_fields,\\n model_process_schema,\\n )\\n from pydantic.v1.schema import (\\n get_annotation_from_field_info as get_annotation_from_field_info,\\n )\\n from pydantic.v1.schema import (\\n get_flat_models_from_field as get_flat_models_from_field,\\n )\\n from pydantic.v1.schema import get_model_name_map as get_model_name_map\\n from pydantic.v1.types import ( # type: ignore[assignment]\\n SecretBytes as SecretBytes,\\n )\\n from pydantic.v1.types import ( # type: ignore[assignment]\\n SecretStr as SecretStr,\\n )\\n from pydantic.v1.typing import evaluate_forwardref as evaluate_forwardref\\n from pydantic.v1.utils import lenient_issubclass as lenient_issubclass\\n else:\\n # Dummy classes for Pydantic v2.12.0+ where pydantic.v1 is dropped\\n BaseConfig = Any\\n BaseModel = Any\\n ValidationError = Any\\n create_model = Any\\n Validator = Any\\n Color = Any\\n ErrorWrapper = Any\\n MissingError = Any\\n SHAPE_FROZENSET = SHAPE_LIST = SHAPE_SEQUENCE = SHAPE_SET = SHAPE_SINGLETON = SHAPE_TUPLE = SHAPE_TUPLE_ELLIPSIS = Any\\n FieldInfo = Any\\n ModelField = Any\\n Undefined = Any\\n UndefinedType = Any\\n AnyUrl = Any\\n NameEmail = Any\\n TypeModelSet = Any\\n field_schema = get_flat_models_from_fields = model_process_schema = Any\\n get_annotation_from_field_info = Any\\n get_flat_models_from_field = Any\\n get_model_name_map = Any\\n SecretBytes = Any\\n SecretStr = Any\\n evaluate_forwardref = Any\\n lenient_issubclass = Any\\n",
"old_string": "else:\\n from pydantic.v1 import BaseConfig as BaseConfig # type: ignore[assignment]\\n from pydantic.v1 import BaseModel as BaseModel # type: ignore[assignment]\\n from pydantic.v1 import ( # type: ignore[assignment]\\n ValidationError as ValidationError,\\n )\\n from pydantic.v1 import create_model as create_model # type: ignore[no-redef]\\n from pydantic.v1.class_validators import Validator as Validator\\n from pydantic.v1.color import Color as Color # type: ignore[assignment]\\n from | {"status": "error", "error_type": "FileEditError", "error_message": "old_string not found in file (tried exact, flexible and regex matching)"}full{"status": "error", "error_type": "FileEditError", "error_message": "old_string not found in file (tried exact, flexible and regex matching)"} |
| 17 | read_file | {
"end_line": 120,
"filepath": "fastapi/_compat/v1.py",
"start_line": 60
} | {"status": "ok", "filepath": "fastapi/_compat/v1.py", "content": " get_flat_models_from_fields,\n model_process_schema,\n )\n from pydantic.schema import (\n gefull{"status": "ok", "filepath": "fastapi/_compat/v1.py", "content": " get_flat_models_from_fields,\n model_process_schema,\n )\n from pydantic.schema import (\n get_annotation_from_field_info as get_annotation_from_field_info,\n )\n from pydantic.schema import get_flat_models_from_field as get_flat_models_from_field\n from pydantic.schema import get_model_name_map as get_model_name_map\n from pydantic.types import SecretBytes as SecretBytes\n from pydantic.types import SecretStr as SecretStr\n from pydantic.typing import evaluate_forwardref as evaluate_forwardref\n from pydantic.utils import lenient_issubclass as lenient_issubclass\n\n\nelse:\n from pydantic.v1 import BaseConfig as BaseConfig # type: ignore[assignment]\n from pydantic.v1 import BaseModel as BaseModel # type: ignore[assignment]\n from pydantic.v1 import ( # type: ignore[assignment]\n ValidationError as ValidationError,\n )\n from pydantic.v1 import create_model as create_model # type: ignore[no-redef]\n from pydantic.v1.class_validators import Validator as Validator\n from pydantic.v1.color import Color as Color # type: ignore[assignment]\n from pydantic.v1.error_wrappers import ErrorWrapper as ErrorWrapper\n from pydantic.v1.errors import MissingError\n from pydantic.v1.fields import (\n SHAPE_FROZENSET,\n SHAPE_LIST,\n SHAPE_SEQUENCE,\n SHAPE_SET,\n SHAPE_SINGLETON,\n SHAPE_TUPLE,\n SHAPE_TUPLE_ELLIPSIS,\n )\n from pydantic.v1.fields import FieldInfo as FieldInfo # type: ignore[assignment]\n from pydantic.v1.fields import ModelField as ModelField\n from pydantic.v1.fields import Undefined as Undefined\n from pydantic.v1.fields import UndefinedType as UndefinedType\n from pydantic.v1.networks import AnyUrl as AnyUrl\n from pydantic.v1.networks import ( # type: ignore[assignment]\n NameEmail as NameEmail,\n )\n from pydantic.v1.sch |
| 18 | edit_file | {
"filepath": "fastapi/_compat/v1.py",
"new_string": "else:\\n if PYDANTIC_V1_SUPPORTED:\\n from pydantic.v1 import BaseConfig as BaseConfig # type: ignore[assignment]\\n from pydantic.v1 import BaseModel as BaseModel # type: ignore[assignment]\\n from pydantic.v1 import ( # type: ignore[assignment]\\n ValidationError as ValidationError,\\n )\\n from pydantic.v1 import create_model as create_model # type: ignore[no-redef]\\n from pydantic.v1.class_validators import Validator as Validator\\n from pydantic.v1.color import Color as Color # type: ignore[assignment]\\n from pydantic.v1.error_wrappers import ErrorWrapper as ErrorWrapper\\n from pydantic.v1.errors import MissingError\\n from pydantic.v1.fields import (\\n SHAPE_FROZENSET,\\n SHAPE_LIST,\\n SHAPE_SEQUENCE,\\n SHAPE_SET,\\n SHAPE_SINGLETON,\\n SHAPE_TUPLE,\\n SHAPE_TUPLE_ELLIPSIS,\\n )\\n from pydantic.v1.fields import FieldInfo as FieldInfo # type: ignore[assignment]\\n from pydantic.v1.fields import ModelField as ModelField\\n from pydantic.v1.fields import Undefined as Undefined\\n from pydantic.v1.fields import UndefinedType as UndefinedType\\n from pydantic.v1.networks import AnyUrl as AnyUrl\\n from pydantic.v1.networks import ( # type: ignore[assignment]\\n NameEmail as NameEmail,\\n )\\n from pydantic.v1.schema import TypeModelSet as TypeModelSet\\n from pydantic.v1.schema import (\\n field_schema,\\n get_flat_models_from_fields,\\n model_process_schema,\\n )\\n from pydantic.v1.schema import (\\n get_annotation_from_field_info as get_annotation_from_field_info,\\n )\\n from pydantic.v1.schema import (\\n get_flat_models_from_field as get_flat_models_from_field,\\n )\\n from pydantic.v1.schema import get_model_name_map as get_model_name_map\\n from pydantic.v1.types import ( # type: ignore[assignment]\\n SecretBytes as SecretBytes,\\n )\\n from pydantic.v1.types import ( # type: ignore[assignment]\\n SecretStr as SecretStr,\\n )\\n from pydantic.v1.typing import evaluate_forwardref as evaluate_forwardref\\n from pydantic.v1.utils import lenient_issubclass as lenient_issubclass\\n else:\\n # Dummy classes for Pydantic v2.12.0+ where pydantic.v1 is dropped\\n BaseConfig = Any\\n BaseModel = Any\\n ValidationError = Any\\n create_model = Any\\n Validator = Any\\n Color = Any\\n ErrorWrapper = Any\\n MissingError = Any\\n SHAPE_FROZENSET = SHAPE_LIST = SHAPE_SEQUENCE = SHAPE_SET = SHAPE_SINGLETON = SHAPE_TUPLE = SHAPE_TUPLE_ELLIPSIS = Any\\n FieldInfo = Any\\n ModelField = Any\\n Undefined = Any\\n UndefinedType = Any\\n AnyUrl = Any\\n NameEmail = Any\\n TypeModelSet = Any\\n field_schema = get_flat_models_from_fields = model_process_schema = Any\\n get_annotation_from_field_info = Any\\n get_flat_models_from_field = Any\\n get_model_name_map = Any\\n SecretBytes = Any\\n SecretStr = Any\\n evaluate_forwardref = Any\\n lenient_issubclass = Any\\n",
"old_string": "else:\\n from pydantic.v1 import BaseConfig as BaseConfig # type: ignore[assignment]\\n from pydantic.v1 import BaseModel as BaseModel # type: ignore[assignment]\\n from pydantic.v1 import ( # type: ignore[assignment]\\n ValidationError as ValidationError,\\n )\\n from pydantic.v1 import create_model as create_model # type: ignore[no-redef]\\n from pydantic.v1.class_validators import Validator as Validator\\n from pydantic.v1.color import Color as Color # type: ignore[assignment]\\n from | {"status": "error", "error_type": "FileEditError", "error_message": "old_string not found in file (tried exact, flexible and regex matching)"}full{"status": "error", "error_type": "FileEditError", "error_message": "old_string not found in file (tried exact, flexible and regex matching)"} |
| 19 | read_file | {
"end_line": 140,
"filepath": "fastapi/_compat/v1.py",
"start_line": 75
} | {"status": "ok", "filepath": "fastapi/_compat/v1.py", "content": " from pydantic.v1 import BaseConfig as BaseConfig # type: ignore[assignment]\n from pydantic.vfull{"status": "ok", "filepath": "fastapi/_compat/v1.py", "content": " from pydantic.v1 import BaseConfig as BaseConfig # type: ignore[assignment]\n from pydantic.v1 import BaseModel as BaseModel # type: ignore[assignment]\n from pydantic.v1 import ( # type: ignore[assignment]\n ValidationError as ValidationError,\n )\n from pydantic.v1 import create_model as create_model # type: ignore[no-redef]\n from pydantic.v1.class_validators import Validator as Validator\n from pydantic.v1.color import Color as Color # type: ignore[assignment]\n from pydantic.v1.error_wrappers import ErrorWrapper as ErrorWrapper\n from pydantic.v1.errors import MissingError\n from pydantic.v1.fields import (\n SHAPE_FROZENSET,\n SHAPE_LIST,\n SHAPE_SEQUENCE,\n SHAPE_SET,\n SHAPE_SINGLETON,\n SHAPE_TUPLE,\n SHAPE_TUPLE_ELLIPSIS,\n )\n from pydantic.v1.fields import FieldInfo as FieldInfo # type: ignore[assignment]\n from pydantic.v1.fields import ModelField as ModelField\n from pydantic.v1.fields import Undefined as Undefined\n from pydantic.v1.fields import UndefinedType as UndefinedType\n from pydantic.v1.networks import AnyUrl as AnyUrl\n from pydantic.v1.networks import ( # type: ignore[assignment]\n NameEmail as NameEmail,\n )\n from pydantic.v1.schema import TypeModelSet as TypeModelSet\n from pydantic.v1.schema import (\n field_schema,\n get_flat_models_from_fields,\n model_process_schema,\n )\n from pydantic.v1.schema import (\n get_annotation_from_field_info as get_annotation_from_field_info,\n )\n from pydantic.v1.schema import (\n get_flat_models_from_field as get_flat_models_from_field,\n )\n from pydantic.v1.schema import get_model_name_map as get_model_name_map\n from pydantic.v1.types import ( # type: ignore[assignment]\n SecretBytes as SecretBytes,\n )\n from pydantic.v1.types import ( |
| 20 | edit_file | {
"filepath": "fastapi/_compat/v1.py",
"new_string": "else:\\n if PYDANTIC_V1_SUPPORTED:\\n from pydantic.v1 import BaseConfig as BaseConfig # type: ignore[assignment]\\n from pydantic.v1 import BaseModel as BaseModel # type: ignore[assignment]\\n from pydantic.v1 import ( # type: ignore[assignment]\\n ValidationError as ValidationError,\\n )\\n from pydantic.v1 import create_model as create_model # type: ignore[no-redef]\\n from pydantic.v1.class_validators import Validator as Validator\\n from pydantic.v1.color import Color as Color # type: ignore[assignment]\\n from pydantic.v1.error_wrappers import ErrorWrapper as ErrorWrapper\\n from pydantic.v1.errors import MissingError\\n from pydantic.v1.fields import (\\n SHAPE_FROZENSET,\\n SHAPE_LIST,\\n SHAPE_SEQUENCE,\\n SHAPE_SET,\\n SHAPE_SINGLETON,\\n SHAPE_TUPLE,\\n SHAPE_TUPLE_ELLIPSIS,\\n )\\n from pydantic.v1.fields import FieldInfo as FieldInfo # type: ignore[assignment]\\n from pydantic.v1.fields import ModelField as ModelField\\n from pydantic.v1.fields import Undefined as Undefined\\n from pydantic.v1.fields import UndefinedType as UndefinedType\\n from pydantic.v1.networks import AnyUrl as AnyUrl\\n from pydantic.v1.networks import ( # type: ignore[assignment]\\n NameEmail as NameEmail,\\n )\\n from pydantic.v1.schema import TypeModelSet as TypeModelSet\\n from pydantic.v1.schema import (\\n field_schema,\\n get_flat_models_from_fields,\\n model_process_schema,\\n )\\n from pydantic.v1.schema import (\\n get_annotation_from_field_info as get_annotation_from_field_info,\\n )\\n from pydantic.v1.schema import (\\n get_flat_models_from_field as get_flat_models_from_field,\\n )\\n from pydantic.v1.schema import get_model_name_map as get_model_name_map\\n from pydantic.v1.types import ( # type: ignore[assignment]\\n SecretBytes as SecretBytes,\\n )\\n from pydantic.v1.types import ( # type: ignore[assignment]\\n SecretStr as SecretStr,\\n )\\n from pydantic.v1.typing import evaluate_forwardref as evaluate_forwardref\\n from pydantic.v1.utils import lenient_issubclass as lenient_issubclass\\n else:\\n # Dummy classes for Pydantic v2.12.0+ where pydantic.v1 is dropped\\n BaseConfig = Any\\n BaseModel = Any\\n ValidationError = Any\\n create_model = Any\\n Validator = Any\\n Color = Any\\n ErrorWrapper = Any\\n MissingError = Any\\n SHAPE_FROZENSET = SHAPE_LIST = SHAPE_SEQUENCE = SHAPE_SET = SHAPE_SINGLETON = SHAPE_TUPLE = SHAPE_TUPLE_ELLIPSIS = Any\\n FieldInfo = Any\\n ModelField = Any\\n Undefined = Any\\n UndefinedType = Any\\n AnyUrl = Any\\n NameEmail = Any\\n TypeModelSet = Any\\n field_schema = get_flat_models_from_fields = model_process_schema = Any\\n get_annotation_from_field_info = Any\\n get_flat_models_from_field = Any\\n get_model_name_map = Any\\n SecretBytes = Any\\n SecretStr = Any\\n evaluate_forwardref = Any\\n lenient_issubclass = Any\\n",
"old_string": "else:\\n from pydantic.v1 import BaseConfig as BaseConfig # type: ignore[assignment]\\n from pydantic.v1 import BaseModel as BaseModel # type: ignore[assignment]\\n from pydantic.v1 import ( # type: ignore[assignment]\\n ValidationError as ValidationError,\\n )\\n from pydantic.v1 import create_model as create_model # type: ignore[no-redef]\\n from pydantic.v1.class_validators import Validator as Validator\\n from pydantic.v1.color import Color as Color # type: ignore[assignment]\\n from | {"status": "error", "error_type": "FileEditError", "error_message": "old_string not found in file (tried exact, flexible and regex matching)"}full{"status": "error", "error_type": "FileEditError", "error_message": "old_string not found in file (tried exact, flexible and regex matching)"} |
| 21 | read_file | {
"end_line": 130,
"filepath": "fastapi/_compat/v1.py",
"start_line": 70
} | {"status": "ok", "filepath": "fastapi/_compat/v1.py", "content": " from pydantic.typing import evaluate_forwardref as evaluate_forwardref\n from pydantic.utils full{"status": "ok", "filepath": "fastapi/_compat/v1.py", "content": " from pydantic.typing import evaluate_forwardref as evaluate_forwardref\n from pydantic.utils import lenient_issubclass as lenient_issubclass\n\n\nelse:\n from pydantic.v1 import BaseConfig as BaseConfig # type: ignore[assignment]\n from pydantic.v1 import BaseModel as BaseModel # type: ignore[assignment]\n from pydantic.v1 import ( # type: ignore[assignment]\n ValidationError as ValidationError,\n )\n from pydantic.v1 import create_model as create_model # type: ignore[no-redef]\n from pydantic.v1.class_validators import Validator as Validator\n from pydantic.v1.color import Color as Color # type: ignore[assignment]\n from pydantic.v1.error_wrappers import ErrorWrapper as ErrorWrapper\n from pydantic.v1.errors import MissingError\n from pydantic.v1.fields import (\n SHAPE_FROZENSET,\n SHAPE_LIST,\n SHAPE_SEQUENCE,\n SHAPE_SET,\n SHAPE_SINGLETON,\n SHAPE_TUPLE,\n SHAPE_TUPLE_ELLIPSIS,\n )\n from pydantic.v1.fields import FieldInfo as FieldInfo # type: ignore[assignment]\n from pydantic.v1.fields import ModelField as ModelField\n from pydantic.v1.fields import Undefined as Undefined\n from pydantic.v1.fields import UndefinedType as UndefinedType\n from pydantic.v1.networks import AnyUrl as AnyUrl\n from pydantic.v1.networks import ( # type: ignore[assignment]\n NameEmail as NameEmail,\n )\n from pydantic.v1.schema import TypeModelSet as TypeModelSet\n from pydantic.v1.schema import (\n field_schema,\n get_flat_models_from_fields,\n model_process_schema,\n )\n from pydantic.v1.schema import (\n get_annotation_from_field_info as get_annotation_from_field_info,\n )\n from pydantic.v1.schema import (\n get_flat_models_from_field as get_flat_models_from_field,\n )\n from pydantic.v1.schema import get_model_name_map as get_ |
diff --git a/fastapi/_compat/v1.py b/fastapi/_compat/v1.py
index f0ac5163..3b8f4d6a 100644
--- a/fastapi/_compat/v1.py
+++ b/fastapi/_compat/v1.py
@@ -21,6 +21,9 @@ from typing_extensions import Literal
PYDANTIC_VERSION_MINOR_TUPLE = tuple(int(x) for x in PYDANTIC_VERSION.split(".")[:2])
PYDANTIC_V2 = PYDANTIC_VERSION_MINOR_TUPLE[0] == 2
+# Pydantic v2.12.0+ drops support for v1 and emits a warning when importing it.
+# We avoid importing pydantic.v1 in these cases to prevent the warning.
+PYDANTIC_V1_SUPPORTED = not (PYDANTIC_V2 and PYDANTIC_VERSION_MINOR_TUPLE[1] >= 12)
# Keeping old "Required" functionality from Pydantic V1, without
# shadowing typing.Required.
RequiredParam: Any = Ellipsis
==================================== ERRORS ====================================
____________________ ERROR collecting tests/test_compat.py _____________________
ImportError while importing test module '/tmp/swe_work/eval4_submission/fastapi_14186/b/workspace/tests/test_compat.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/root/.local/share/uv/python/cpython-3.13.14-linux-x86_64-gnu/lib/python3.13/importlib/__init__.py:88: in import_module
return _bootstrap._gcd_import(name[level:], package, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
tests/test_compat.py:4: in <module>
from fastapi._compat import (
E ImportError: cannot import name 'may_v1' from 'fastapi._compat' (/tmp/swe_work/eval4_submission/fastapi_14186/b/workspace/fastapi/_compat/__init__.py)
!!!!!!!!!!!!!!!!!!!!!!!!!! stopping after 1 failures !!!!!!!!!!!!!!!!!!!!!!!!!!!
1 error in 0.58s