ul-api-utils 8.1.9__py3-none-any.whl → 8.1.11__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 ul-api-utils might be problematic. Click here for more details.

@@ -1,5 +1,5 @@
1
1
  import inspect
2
- from typing import NamedTuple, Any, Callable, Optional, List, Dict, Type, Tuple, TYPE_CHECKING
2
+ from typing import NamedTuple, Any, Callable, Optional, List, Dict, Type, Tuple, TYPE_CHECKING, Union, get_origin, get_args
3
3
 
4
4
  from flask import request
5
5
  from pydantic import BaseModel, ValidationError, validate_call, TypeAdapter
@@ -25,6 +25,18 @@ if TYPE_CHECKING:
25
25
  FN_SYSTEM_PROPS = {"api_resource", "query", "body", "return", "body_validation_error", "query_validation_error"}
26
26
 
27
27
 
28
+ def _is_complex_type(annotation):
29
+ origin = get_origin(annotation)
30
+
31
+ # Optional[type_] is typing.Union
32
+ if origin is Union:
33
+ return any(_is_complex_type(arg) for arg in get_args(annotation))
34
+
35
+ if origin is None:
36
+ return annotation not in (str, int, float, bool, type(None))
37
+
38
+ return origin in (list, dict, tuple, set)
39
+
28
40
  def _patch_errors(dest_errors: List[Dict[str, str]], errors: List[ErrorDetails], kind: str) -> List[Dict[str, str]]:
29
41
  for error in errors:
30
42
  dest_errors.append({
@@ -156,7 +168,9 @@ class ApiResourceFnTyping(NamedTuple):
156
168
  return kwargs, errors
157
169
  body = self._get_body()
158
170
  try:
159
- kwargs['body'] = TypeAdapter(Type[BaseModel | List[BaseModel]]).validate_python(body)
171
+ expected_typing: Type[BaseModel | List[BaseModel]] = List[self.body_typing] \
172
+ if self.request_body_many else self.body_typing
173
+ kwargs['body'] = TypeAdapter(expected_typing).validate_python(body)
160
174
  except ValidationError as ve:
161
175
  if self.has_body_validation_error:
162
176
  kwargs['body_validation_error'] = ve
@@ -168,11 +182,13 @@ class ApiResourceFnTyping(NamedTuple):
168
182
  if self.query_typing is None:
169
183
  return kwargs, errors
170
184
  try:
171
- is_complex_field = lambda field: field.annotation and not isinstance(field.annotation, (str, int, float, bool, type(None))) # noqa: E731
172
185
  kwargs["query"] = set_model(self.query_typing, {
173
186
  **request.args.to_dict(),
174
- **{key: value for key, value in request.args.to_dict(flat=False).items()
175
- if key in self.query_typing.model_fields and is_complex_field(self.query_typing.model_fields[key])},
187
+ **{
188
+ key: value for key, value in request.args.to_dict(flat=False).items()
189
+ if key in self.query_typing.model_fields
190
+ and _is_complex_type(self.query_typing.model_fields[key].annotation)
191
+ },
176
192
  })
177
193
  except ValidationError as ve:
178
194
  if self.has_query_validation_error:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ul-api-utils
3
- Version: 8.1.9
3
+ Version: 8.1.11
4
4
  Summary: Python api utils
5
5
  Author: Unic-lab
6
6
  Author-email:
@@ -29,7 +29,7 @@ ul_api_utils/api_resource/api_request.py,sha256=6Ag2trKIkenhYYPU2--hnfNJC5lLgBxV
29
29
  ul_api_utils/api_resource/api_resource.py,sha256=j-E8KJiXWS1L0oVIerJZlbGpDL2ijlQrck4GrJPWPyE,17840
30
30
  ul_api_utils/api_resource/api_resource_config.py,sha256=l9OYJy75UZLshOkEQDO5jlhXeb5H4HDPu-nLOjuoexw,769
31
31
  ul_api_utils/api_resource/api_resource_error_handling.py,sha256=E0SWpjFSIP-4SumbgzrHtFuFiGe9q38WsvLROt0YcPE,1168
32
- ul_api_utils/api_resource/api_resource_fn_typing.py,sha256=8aCYTHClOiP6Y3s1gS7j3_yRNNmiM3YdqqiPQN-tWbU,18624
32
+ ul_api_utils/api_resource/api_resource_fn_typing.py,sha256=o-S6ep9fhSgZzQCv1lbpEojVLWcpFwaGP1CiS7GcFlk,19063
33
33
  ul_api_utils/api_resource/api_resource_type.py,sha256=mgjSQI3swGpgpLI6y35LYtFrdN-kXyV5cQorwGW7h6g,462
34
34
  ul_api_utils/api_resource/api_response.py,sha256=z1Hf9UQ1nQDzhmyykUkEEd5ltXiIfK3CO_F2ee4-UcY,10026
35
35
  ul_api_utils/api_resource/api_response_db.py,sha256=ucY6ANPlHZml7JAbvq-PL85z0bvERTjEJKvz-REPyok,888
@@ -148,9 +148,9 @@ ul_api_utils/validators/validate_empty_object.py,sha256=3Ck_iwyJE_M5e7l6s1i88aqb
148
148
  ul_api_utils/validators/validate_uuid.py,sha256=EfvlRirv2EW0Z6w3s8E8rUa9GaI8qXZkBWhnPs8NFrA,257
149
149
  ul_api_utils/validators/__tests__/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
150
150
  ul_api_utils/validators/__tests__/test_custom_fields.py,sha256=20gLlnm1Ithsbbz3NIUXVAd92lW6YwVRSg_nETZhfaI,1442
151
- ul_api_utils-8.1.9.dist-info/LICENSE,sha256=6Qo8OdcqI8aGrswJKJYhST-bYqxVQBQ3ujKdTSdq-80,1062
152
- ul_api_utils-8.1.9.dist-info/METADATA,sha256=yVTdT2Qw39cQRjLmOncL8-rRZXQl-4Dj8-Ik8GbvJT0,14747
153
- ul_api_utils-8.1.9.dist-info/WHEEL,sha256=G16H4A3IeoQmnOrYV4ueZGKSjhipXx8zc8nu9FGlvMA,92
154
- ul_api_utils-8.1.9.dist-info/entry_points.txt,sha256=8tL3ySHWTyJMuV1hx1fHfN8zumDVOCOm63w3StphkXg,53
155
- ul_api_utils-8.1.9.dist-info/top_level.txt,sha256=1XsW8iOSFaH4LOzDcnNyxHpHrbKU3fSn-aIAxe04jmw,21
156
- ul_api_utils-8.1.9.dist-info/RECORD,,
151
+ ul_api_utils-8.1.11.dist-info/LICENSE,sha256=6Qo8OdcqI8aGrswJKJYhST-bYqxVQBQ3ujKdTSdq-80,1062
152
+ ul_api_utils-8.1.11.dist-info/METADATA,sha256=HPyfE6xcsaUaiFaDMEBwOBvEa_h1-jkpcUAQtZJXR5M,14748
153
+ ul_api_utils-8.1.11.dist-info/WHEEL,sha256=G16H4A3IeoQmnOrYV4ueZGKSjhipXx8zc8nu9FGlvMA,92
154
+ ul_api_utils-8.1.11.dist-info/entry_points.txt,sha256=8tL3ySHWTyJMuV1hx1fHfN8zumDVOCOm63w3StphkXg,53
155
+ ul_api_utils-8.1.11.dist-info/top_level.txt,sha256=1XsW8iOSFaH4LOzDcnNyxHpHrbKU3fSn-aIAxe04jmw,21
156
+ ul_api_utils-8.1.11.dist-info/RECORD,,