fastapi 0.118.2__py3-none-any.whl → 0.119.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of fastapi might be problematic. Click here for more details.

fastapi/utils.py CHANGED
@@ -23,10 +23,12 @@ from fastapi._compat import (
23
23
  Undefined,
24
24
  UndefinedType,
25
25
  Validator,
26
+ annotation_is_pydantic_v1,
26
27
  lenient_issubclass,
28
+ v1,
27
29
  )
28
30
  from fastapi.datastructures import DefaultPlaceholder, DefaultType
29
- from pydantic import BaseModel, create_model
31
+ from pydantic import BaseModel
30
32
  from pydantic.fields import FieldInfo
31
33
  from typing_extensions import Literal
32
34
 
@@ -60,50 +62,70 @@ def get_path_param_names(path: str) -> Set[str]:
60
62
  return set(re.findall("{(.*?)}", path))
61
63
 
62
64
 
65
+ _invalid_args_message = (
66
+ "Invalid args for response field! Hint: "
67
+ "check that {type_} is a valid Pydantic field type. "
68
+ "If you are using a return type annotation that is not a valid Pydantic "
69
+ "field (e.g. Union[Response, dict, None]) you can disable generating the "
70
+ "response model from the type annotation with the path operation decorator "
71
+ "parameter response_model=None. Read more: "
72
+ "https://fastapi.tiangolo.com/tutorial/response-model/"
73
+ )
74
+
75
+
63
76
  def create_model_field(
64
77
  name: str,
65
78
  type_: Any,
66
79
  class_validators: Optional[Dict[str, Validator]] = None,
67
80
  default: Optional[Any] = Undefined,
68
81
  required: Union[bool, UndefinedType] = Undefined,
69
- model_config: Type[BaseConfig] = BaseConfig,
82
+ model_config: Union[Type[BaseConfig], None] = None,
70
83
  field_info: Optional[FieldInfo] = None,
71
84
  alias: Optional[str] = None,
72
85
  mode: Literal["validation", "serialization"] = "validation",
86
+ version: Literal["1", "auto"] = "auto",
73
87
  ) -> ModelField:
74
88
  class_validators = class_validators or {}
75
- if PYDANTIC_V2:
89
+
90
+ v1_model_config = v1.BaseConfig
91
+ v1_field_info = field_info or v1.FieldInfo()
92
+ v1_kwargs = {
93
+ "name": name,
94
+ "field_info": v1_field_info,
95
+ "type_": type_,
96
+ "class_validators": class_validators,
97
+ "default": default,
98
+ "required": required,
99
+ "model_config": v1_model_config,
100
+ "alias": alias,
101
+ }
102
+
103
+ if (
104
+ annotation_is_pydantic_v1(type_)
105
+ or isinstance(field_info, v1.FieldInfo)
106
+ or version == "1"
107
+ ):
108
+ try:
109
+ return v1.ModelField(**v1_kwargs) # type: ignore[no-any-return]
110
+ except RuntimeError:
111
+ raise fastapi.exceptions.FastAPIError(_invalid_args_message) from None
112
+ elif PYDANTIC_V2:
113
+ from ._compat import v2
114
+
76
115
  field_info = field_info or FieldInfo(
77
116
  annotation=type_, default=default, alias=alias
78
117
  )
79
- else:
80
- field_info = field_info or FieldInfo()
81
- kwargs = {"name": name, "field_info": field_info}
82
- if PYDANTIC_V2:
83
- kwargs.update({"mode": mode})
84
- else:
85
- kwargs.update(
86
- {
87
- "type_": type_,
88
- "class_validators": class_validators,
89
- "default": default,
90
- "required": required,
91
- "model_config": model_config,
92
- "alias": alias,
93
- }
94
- )
118
+ kwargs = {"mode": mode, "name": name, "field_info": field_info}
119
+ try:
120
+ return v2.ModelField(**kwargs) # type: ignore[return-value,arg-type]
121
+ except PydanticSchemaGenerationError:
122
+ raise fastapi.exceptions.FastAPIError(_invalid_args_message) from None
123
+ # Pydantic v2 is not installed, but it's not a Pydantic v1 ModelField, it could be
124
+ # a Pydantic v1 type, like a constrained int
95
125
  try:
96
- return ModelField(**kwargs) # type: ignore[arg-type]
97
- except (RuntimeError, PydanticSchemaGenerationError):
98
- raise fastapi.exceptions.FastAPIError(
99
- "Invalid args for response field! Hint: "
100
- f"check that {type_} is a valid Pydantic field type. "
101
- "If you are using a return type annotation that is not a valid Pydantic "
102
- "field (e.g. Union[Response, dict, None]) you can disable generating the "
103
- "response model from the type annotation with the path operation decorator "
104
- "parameter response_model=None. Read more: "
105
- "https://fastapi.tiangolo.com/tutorial/response-model/"
106
- ) from None
126
+ return v1.ModelField(**v1_kwargs) # type: ignore[no-any-return]
127
+ except RuntimeError:
128
+ raise fastapi.exceptions.FastAPIError(_invalid_args_message) from None
107
129
 
108
130
 
109
131
  def create_cloned_field(
@@ -112,7 +134,10 @@ def create_cloned_field(
112
134
  cloned_types: Optional[MutableMapping[Type[BaseModel], Type[BaseModel]]] = None,
113
135
  ) -> ModelField:
114
136
  if PYDANTIC_V2:
115
- return field
137
+ from ._compat import v2
138
+
139
+ if isinstance(field, v2.ModelField):
140
+ return field
116
141
  # cloned_types caches already cloned types to support recursive models and improve
117
142
  # performance by avoiding unnecessary cloning
118
143
  if cloned_types is None:
@@ -122,17 +147,18 @@ def create_cloned_field(
122
147
  if is_dataclass(original_type) and hasattr(original_type, "__pydantic_model__"):
123
148
  original_type = original_type.__pydantic_model__
124
149
  use_type = original_type
125
- if lenient_issubclass(original_type, BaseModel):
126
- original_type = cast(Type[BaseModel], original_type)
150
+ if lenient_issubclass(original_type, v1.BaseModel):
151
+ original_type = cast(Type[v1.BaseModel], original_type)
127
152
  use_type = cloned_types.get(original_type)
128
153
  if use_type is None:
129
- use_type = create_model(original_type.__name__, __base__=original_type)
154
+ use_type = v1.create_model(original_type.__name__, __base__=original_type)
130
155
  cloned_types[original_type] = use_type
131
156
  for f in original_type.__fields__.values():
132
157
  use_type.__fields__[f.name] = create_cloned_field(
133
- f, cloned_types=cloned_types
158
+ f,
159
+ cloned_types=cloned_types,
134
160
  )
135
- new_field = create_model_field(name=field.name, type_=use_type)
161
+ new_field = create_model_field(name=field.name, type_=use_type, version="1")
136
162
  new_field.has_alias = field.has_alias # type: ignore[attr-defined]
137
163
  new_field.alias = field.alias # type: ignore[misc]
138
164
  new_field.class_validators = field.class_validators # type: ignore[attr-defined]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: fastapi
3
- Version: 0.118.2
3
+ Version: 0.119.0
4
4
  Summary: FastAPI framework, high performance, easy to learn, fast to code, ready for production
5
5
  Author-Email: =?utf-8?q?Sebasti=C3=A1n_Ram=C3=ADrez?= <tiangolo@gmail.com>
6
6
  Classifier: Intended Audience :: Information Technology
@@ -30,6 +30,7 @@ Classifier: Programming Language :: Python :: 3.10
30
30
  Classifier: Programming Language :: Python :: 3.11
31
31
  Classifier: Programming Language :: Python :: 3.12
32
32
  Classifier: Programming Language :: Python :: 3.13
33
+ Classifier: Programming Language :: Python :: 3.14
33
34
  Classifier: Topic :: Internet :: WWW/HTTP :: HTTP Servers
34
35
  Classifier: Topic :: Internet :: WWW/HTTP
35
36
  Project-URL: Homepage, https://github.com/fastapi/fastapi
@@ -1,19 +1,24 @@
1
- fastapi-0.118.2.dist-info/METADATA,sha256=yrkrXAQmgRf8K6sPfw5HCFzK8cTuCYbqOMTPdbYiaDU,28135
2
- fastapi-0.118.2.dist-info/WHEEL,sha256=9P2ygRxDrTJz3gsagc0Z96ukrxjr-LFBGOgv3AuKlCA,90
3
- fastapi-0.118.2.dist-info/entry_points.txt,sha256=GCf-WbIZxyGT4MUmrPGj1cOHYZoGsNPHAvNkT6hnGeA,61
4
- fastapi-0.118.2.dist-info/licenses/LICENSE,sha256=Tsif_IFIW5f-xYSy1KlhAy7v_oNEU4lP2cEnSQbMdE4,1086
5
- fastapi/__init__.py,sha256=r514dIK-FjZ0GBeqdtq5TSIaheEY4WiYLBgSb6noK8o,1081
1
+ fastapi-0.119.0.dist-info/METADATA,sha256=9RzosSkC2zNwdliJ2_sosixubAhbDq4t-tyvZDMDlwg,28186
2
+ fastapi-0.119.0.dist-info/WHEEL,sha256=9P2ygRxDrTJz3gsagc0Z96ukrxjr-LFBGOgv3AuKlCA,90
3
+ fastapi-0.119.0.dist-info/entry_points.txt,sha256=GCf-WbIZxyGT4MUmrPGj1cOHYZoGsNPHAvNkT6hnGeA,61
4
+ fastapi-0.119.0.dist-info/licenses/LICENSE,sha256=Tsif_IFIW5f-xYSy1KlhAy7v_oNEU4lP2cEnSQbMdE4,1086
5
+ fastapi/__init__.py,sha256=q4QtrQP-eBRDVvKeyEyir7ClYWTW2YcB7JMBaMQOGbI,1081
6
6
  fastapi/__main__.py,sha256=bKePXLdO4SsVSM6r9SVoLickJDcR2c0cTOxZRKq26YQ,37
7
- fastapi/_compat.py,sha256=gK1ZeDQYNr6gBYY0Hefr2HZiEawOCuDqm021uU1xOTs,25041
7
+ fastapi/_compat/__init__.py,sha256=WHnNsyqIJDrQL4XFQnnGVzaasRiJ3tP7aLWbtaJmj9k,2702
8
+ fastapi/_compat/main.py,sha256=zWbuXdKsPWU2A23x1UYwpAFbAG7PPJLkv5l6rFz2EJo,9577
9
+ fastapi/_compat/model_field.py,sha256=SrSoXEcloGXKAqjR8UDW2869RPgLRFdWTuVgTBhX_Gw,1190
10
+ fastapi/_compat/shared.py,sha256=T8bSTUX_NQX0i5-i25C2GY7hQV6q2jDvNzWW2j3t57k,6992
11
+ fastapi/_compat/v1.py,sha256=yhBcElJKJTgnMUEKWH2NJfUcm5zpRouUk4AgVHGNBs8,11015
12
+ fastapi/_compat/v2.py,sha256=2Y8u4LGo9qlbGablSfLt2HN-qy9mdEdWm8XjQCS-rVI,15830
8
13
  fastapi/applications.py,sha256=nLbGcVdmCxXsl4aTSuP0WVS_XGY7wXBL3vC7nqlplmA,180276
9
14
  fastapi/background.py,sha256=rouLirxUANrcYC824MSMypXL_Qb2HYg2YZqaiEqbEKI,1768
10
15
  fastapi/cli.py,sha256=OYhZb0NR_deuT5ofyPF2NoNBzZDNOP8Salef2nk-HqA,418
11
16
  fastapi/concurrency.py,sha256=MirfowoSpkMQZ8j_g0ZxaQKpV6eB3G-dB5TgcXCrgEA,1424
12
- fastapi/datastructures.py,sha256=b2PEz77XGq-u3Ur1Inwk0AGjOsQZO49yF9C7IPJ15cY,5766
17
+ fastapi/datastructures.py,sha256=hM5DM_PtV7rL54VHtLk0dA9RHeAm9IzBd5TrRqc9tSs,5788
13
18
  fastapi/dependencies/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
14
19
  fastapi/dependencies/models.py,sha256=Pjl6vx-4nZ5Tta9kJa3-RfQKkXtCpS09-FhMgs9eWNs,1507
15
- fastapi/dependencies/utils.py,sha256=WVgX-cF_H318wOlsZSiAP2mX6-puEsx_MAQ6AHSzITE,36814
16
- fastapi/encoders.py,sha256=r_fOgMylrlnCDTh3W9u2W0ZsHTJqIhLpU6QipHMy0m8,11119
20
+ fastapi/dependencies/utils.py,sha256=Zu-cYUeRm3vHXpcRlp3SSGpAlvY9qy_6w47zV7xs4ms,38587
21
+ fastapi/encoders.py,sha256=rWunWAUY41X5ubkwdNewqL9T-zSTxtdUd7QwoqdgNio,11282
17
22
  fastapi/exception_handlers.py,sha256=YVcT8Zy021VYYeecgdyh5YEUjEIHKcLspbkSf4OfbJI,1275
18
23
  fastapi/exceptions.py,sha256=taNixuFEXb67lI1bnX1ubq8y8TseJ4yoPlWjyP0fTzk,4969
19
24
  fastapi/logger.py,sha256=I9NNi3ov8AcqbsbC9wl1X-hdItKgYt2XTrx1f99Zpl4,54
@@ -28,13 +33,13 @@ fastapi/openapi/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
28
33
  fastapi/openapi/constants.py,sha256=adGzmis1L1HJRTE3kJ5fmHS_Noq6tIY6pWv_SFzoFDU,153
29
34
  fastapi/openapi/docs.py,sha256=zSDv4xY6XHcKsaG4zyk1HqSnrZtfZFBB0J7ZBk5YHPE,10345
30
35
  fastapi/openapi/models.py,sha256=m1BNHxf_RiDTK1uCfMre6XZN5y7krZNA62QEP_2EV9s,15625
31
- fastapi/openapi/utils.py,sha256=ZI-nwdT2PtX8kaRPJylZo4LJHjYAcoVGxkd181P75x4,23997
36
+ fastapi/openapi/utils.py,sha256=2DkhvMHoHLI58vK4vai_7v9WZ3R5RMB6dGDIAx3snGo,23255
32
37
  fastapi/param_functions.py,sha256=JHNPLIYvoAwdnZZavIVsxOat8x23fX_Kl33reh7HKl8,64019
33
38
  fastapi/params.py,sha256=SnkGa4nNdmRek6oOELBHcSieRGjYvDPTla3EOl5Zlis,28413
34
39
  fastapi/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
35
40
  fastapi/requests.py,sha256=zayepKFcienBllv3snmWI20Gk0oHNVLU4DDhqXBb4LU,142
36
41
  fastapi/responses.py,sha256=QNQQlwpKhQoIPZTTWkpc9d_QGeGZ_aVQPaDV3nQ8m7c,1761
37
- fastapi/routing.py,sha256=tK_d2K_0kP-rcbAmjjlR0mZMR170QkBITvwHWPq7eiQ,178409
42
+ fastapi/routing.py,sha256=oyDRSG8sOL53dDlduKwJXIb_i0_1TeQduQpKu00T5SU,178480
38
43
  fastapi/security/__init__.py,sha256=bO8pNmxqVRXUjfl2mOKiVZLn0FpBQ61VUYVjmppnbJw,881
39
44
  fastapi/security/api_key.py,sha256=di-0gQ8MKugi2YfmlMoDHk-QMF_vnLGJRFOA6tcZ7fA,9016
40
45
  fastapi/security/base.py,sha256=dl4pvbC-RxjfbWgPtCWd8MVU-7CB2SZ22rJDXVCXO6c,141
@@ -43,9 +48,10 @@ fastapi/security/oauth2.py,sha256=rKHIUHq29367Qpe0Ez5Gcu1yIIM6SMw7nEfh15gBNIQ,22
43
48
  fastapi/security/open_id_connect_url.py,sha256=8vizZ2tGqEp1ur8SwtVgyHJhGAJ5AqahgcvSpaIioDI,2722
44
49
  fastapi/security/utils.py,sha256=bd8T0YM7UQD5ATKucr1bNtAvz_Y3__dVNAv5UebiPvc,293
45
50
  fastapi/staticfiles.py,sha256=iirGIt3sdY2QZXd36ijs3Cj-T0FuGFda3cd90kM9Ikw,69
51
+ fastapi/temp_pydantic_v1_params.py,sha256=DjlXo_wtbNERtLj4jLNMoytb9y4TIpKxKnk-mx93WKY,26526
46
52
  fastapi/templating.py,sha256=4zsuTWgcjcEainMJFAlW6-gnslm6AgOS1SiiDWfmQxk,76
47
53
  fastapi/testclient.py,sha256=nBvaAmX66YldReJNZXPOk1sfuo2Q6hs8bOvIaCep6LQ,66
48
54
  fastapi/types.py,sha256=nFb36sK3DSoqoyo7Miwy3meKK5UdFBgkAgLSzQlUVyI,383
49
- fastapi/utils.py,sha256=S59stPvKPUJ7MSkke3FaegSyig_4Uwhd32jnLiMF1jE,8032
55
+ fastapi/utils.py,sha256=CmeQxdHE9c-_R5Fl_xRT-Uapbm9dHDVYbrB_LAX8MiI,8881
50
56
  fastapi/websockets.py,sha256=419uncYObEKZG0YcrXscfQQYLSWoE10jqxVMetGdR98,222
51
- fastapi-0.118.2.dist-info/RECORD,,
57
+ fastapi-0.119.0.dist-info/RECORD,,