cadwyn 3.4.2__py3-none-any.whl → 3.4.4__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 cadwyn might be problematic. Click here for more details.

@@ -64,8 +64,6 @@ class _ImportedModule:
64
64
  module = f"{self.path}.{self.name}"
65
65
  name = ast.alias(name="*")
66
66
  level = self.how_far_up_is_base_schema_dir_from_current_module
67
- if level == 2 and self.is_package:
68
- level -= 1
69
67
 
70
68
  return ast.ImportFrom(
71
69
  level=level,
cadwyn/exceptions.py CHANGED
@@ -25,6 +25,10 @@ class RouterGenerationError(CadwynError):
25
25
  pass
26
26
 
27
27
 
28
+ class RouterPathParamsModifiedError(RouterGenerationError):
29
+ pass
30
+
31
+
28
32
  class RouteAlreadyExistsError(RouterGenerationError):
29
33
  def __init__(self, *routes: APIRoute):
30
34
  self.routes = routes
cadwyn/routing.py CHANGED
@@ -1,5 +1,6 @@
1
1
  import functools
2
2
  import inspect
3
+ import re
3
4
  import sys
4
5
  import typing
5
6
  import warnings
@@ -45,7 +46,13 @@ from typing_extensions import Self, assert_never
45
46
  from cadwyn._compat import model_fields, rebuild_fastapi_body_param
46
47
  from cadwyn._package_utils import get_package_path_from_module, get_version_dir_path
47
48
  from cadwyn._utils import Sentinel, UnionType, get_another_version_of_module
48
- from cadwyn.exceptions import CadwynError, ModuleIsNotVersionedError, RouteAlreadyExistsError, RouterGenerationError
49
+ from cadwyn.exceptions import (
50
+ CadwynError,
51
+ ModuleIsNotVersionedError,
52
+ RouteAlreadyExistsError,
53
+ RouterGenerationError,
54
+ RouterPathParamsModifiedError,
55
+ )
49
56
  from cadwyn.structure import Version, VersionBundle
50
57
  from cadwyn.structure.common import Endpoint, VersionDate
51
58
  from cadwyn.structure.endpoints import (
@@ -624,6 +631,19 @@ def _apply_endpoint_had_instruction(
624
631
  " It means that your version change has no effect on the attribute"
625
632
  " and can be removed.",
626
633
  )
634
+ if attr_name == "path":
635
+ original_path_params = {p.alias for p in original_route.dependant.path_params}
636
+ new_path_params = set(re.findall("{(.*?)}", attr))
637
+ if new_path_params != original_path_params:
638
+ raise RouterPathParamsModifiedError(
639
+ f'When altering the path of "{original_route.path}" in "{version_change.__name__}",'
640
+ " you have tried to change its path params "
641
+ f'from "{list(original_route.methods)}" to "{list(new_path_params)}". It is not allowed to '
642
+ "change the path params of a route because the endpoint was created to handle the old path "
643
+ "params. In fact, there is no need to change them because the change of path params is "
644
+ "not a breaking change. If you really need to change the path params, you should create a "
645
+ "new route with the new path params and delete the old one.",
646
+ )
627
647
  setattr(original_route, attr_name, attr)
628
648
 
629
649
 
@@ -303,13 +303,13 @@ class VersionBundle:
303
303
  self,
304
304
  body_type: type[BaseModel] | None,
305
305
  latest_dependant_with_internal_schema: Dependant,
306
+ path: str,
306
307
  request: FastapiRequest,
307
308
  response: FastapiResponse,
308
309
  request_info: RequestInfo,
309
310
  current_version: VersionDate,
310
311
  latest_route: APIRoute,
311
312
  ) -> dict[str, Any]:
312
- path = request.scope["path"]
313
313
  method = request.method
314
314
  for v in reversed(self.versions):
315
315
  if v.value <= current_version:
@@ -363,7 +363,6 @@ class VersionBundle:
363
363
  Returns:
364
364
  Modified data
365
365
  """
366
-
367
366
  for v in self.versions:
368
367
  if v.value <= current_version:
369
368
  break
@@ -396,7 +395,6 @@ class VersionBundle:
396
395
  async def decorator(*args: Any, **kwargs: Any) -> _R:
397
396
  request: FastapiRequest = kwargs[request_param_name]
398
397
  response: FastapiResponse = kwargs[response_param_name]
399
- path = request.scope["path"]
400
398
  method = request.method
401
399
  kwargs = await self._convert_endpoint_kwargs_to_version(
402
400
  template_module_body_field_for_request_migrations,
@@ -413,7 +411,7 @@ class VersionBundle:
413
411
  return await self._convert_endpoint_response_to_version(
414
412
  endpoint,
415
413
  latest_route,
416
- path,
414
+ route,
417
415
  method,
418
416
  response_param_name,
419
417
  kwargs,
@@ -433,7 +431,7 @@ class VersionBundle:
433
431
  self,
434
432
  func_to_get_response_from: Endpoint,
435
433
  latest_route: APIRoute,
436
- path: str,
434
+ route: APIRoute,
437
435
  method: str,
438
436
  response_param_name: str,
439
437
  kwargs: dict[str, Any],
@@ -480,7 +478,7 @@ class VersionBundle:
480
478
  response_info,
481
479
  api_version,
482
480
  latest_route,
483
- path,
481
+ route.path,
484
482
  method,
485
483
  )
486
484
  if isinstance(response_or_response_body, FastapiResponse):
@@ -545,6 +543,7 @@ class VersionBundle:
545
543
  new_kwargs = await self._migrate_request(
546
544
  template_module_body_field_for_request_migrations,
547
545
  latest_dependant_with_internal_schema,
546
+ route.path,
548
547
  request,
549
548
  response,
550
549
  request_info,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: cadwyn
3
- Version: 3.4.2
3
+ Version: 3.4.4
4
4
  Summary: Production-ready community-driven modern Stripe-like API versioning in FastAPI
5
5
  Home-page: https://github.com/zmievsa/cadwyn
6
6
  License: MIT
@@ -13,12 +13,12 @@ cadwyn/codegen/_plugins/class_migrations.py,sha256=dbmXMdfUGA2X4phsNdtRQQde4SuoO
13
13
  cadwyn/codegen/_plugins/class_rebuilding.py,sha256=mJR297bqsLUfP4HW5_1GuHlpiYSQd851yHpG_ajjilg,3703
14
14
  cadwyn/codegen/_plugins/class_renaming.py,sha256=5ka2W1c18i4maNbEkEpELvGLEFbd8tthvQX3YA3Bu0A,1843
15
15
  cadwyn/codegen/_plugins/import_auto_adding.py,sha256=00zGK99cT-bq2eXKDlYBR5-Z3uHLOGU7dbhB0YFFrt0,2613
16
- cadwyn/codegen/_plugins/latest_version_aliasing.py,sha256=itVCGc1x3TRwr9O_-hcQBrVBe0P_6dNgKxuSncjX2AY,4012
16
+ cadwyn/codegen/_plugins/latest_version_aliasing.py,sha256=9MPW-FMOcjBZ7L05T0sxwSDCfFZHAn6xZV_E1KImbUA,3946
17
17
  cadwyn/codegen/_plugins/module_migrations.py,sha256=TeWJk4Iu4SRQ9K2iI3v3sCs1110jrltKlPdfU9mXIsQ,722
18
- cadwyn/exceptions.py,sha256=XOLsT4EH1uGNirmKlkgEk03PjUMtD7tgaCDadt_eBbE,695
18
+ cadwyn/exceptions.py,sha256=0nvauw2r5VOaTg9tQ9TZgLdQd3xiqqi6YD7e3-vOcVs,766
19
19
  cadwyn/main.py,sha256=_hC2Ke1uwtnjg2WueDXlg_QnzFgJbTcAlpHgqUBTmg4,4899
20
20
  cadwyn/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
21
- cadwyn/routing.py,sha256=3H8GKT10wAYroAOCtGCNBMuA63SGAQSESze3EhBLwo0,34433
21
+ cadwyn/routing.py,sha256=85xqLfRuLtYwyoFl97ITHPNBSnoN7wP9a_mjyEDAJDc,35563
22
22
  cadwyn/structure/__init__.py,sha256=BjFPlQYCw8ds_4zxdCi2LimarUGqSzyTNmOdT-FkGms,661
23
23
  cadwyn/structure/common.py,sha256=6Z4nI97XPWTCinn6np73m-rLPyYNrz2fWXKJlqjsiaQ,269
24
24
  cadwyn/structure/data.py,sha256=cCaclB67mKlgRiydPFijyfLdng4qyqnY_hP8ApS5pT4,5781
@@ -26,9 +26,9 @@ cadwyn/structure/endpoints.py,sha256=VngfAydGBwekhV2tBOtNDPVgl3X1IgYxUCw--VZ5cQY
26
26
  cadwyn/structure/enums.py,sha256=iMokxA2QYJ61SzyB-Pmuq3y7KL7-e6TsnjLVUaVZQnw,954
27
27
  cadwyn/structure/modules.py,sha256=1FK-lLm-zOTXEvn-QtyBH38aDRht5PDQiZrOPCsBlM4,1268
28
28
  cadwyn/structure/schemas.py,sha256=LIKwDuzorVC9AHg4EN-UYdI133lCk_2MkBTdiyAr-EQ,8808
29
- cadwyn/structure/versions.py,sha256=kmIJTJpihXsCnE7-7PT82nIcW3qkOtN5ewuF3bxnamc,28392
30
- cadwyn-3.4.2.dist-info/entry_points.txt,sha256=eO05hLn9GoRzzpwT9GONPmXKsonjuMNssM2D2WHWKGk,46
31
- cadwyn-3.4.2.dist-info/LICENSE,sha256=KeCWewiDQYpmSnzF-p_0YpoWiyDcUPaCuG8OWQs4ig4,1072
32
- cadwyn-3.4.2.dist-info/WHEEL,sha256=vxFmldFsRN_Hx10GDvsdv1wroKq8r5Lzvjp6GZ4OO8c,88
33
- cadwyn-3.4.2.dist-info/METADATA,sha256=s4cO22vjgaJU5gokr8L2_-osjw4ufSZhE6CYY7Vi6O8,4264
34
- cadwyn-3.4.2.dist-info/RECORD,,
29
+ cadwyn/structure/versions.py,sha256=YSAPrGOIesWtVI-CW5gEMbzNops5idMKeeksBGcJaMY,28365
30
+ cadwyn-3.4.4.dist-info/entry_points.txt,sha256=eO05hLn9GoRzzpwT9GONPmXKsonjuMNssM2D2WHWKGk,46
31
+ cadwyn-3.4.4.dist-info/LICENSE,sha256=KeCWewiDQYpmSnzF-p_0YpoWiyDcUPaCuG8OWQs4ig4,1072
32
+ cadwyn-3.4.4.dist-info/WHEEL,sha256=vxFmldFsRN_Hx10GDvsdv1wroKq8r5Lzvjp6GZ4OO8c,88
33
+ cadwyn-3.4.4.dist-info/METADATA,sha256=cW1suk85sWnkSQYswqck6ho5NxtbwGmUAIgOin1MPWc,4264
34
+ cadwyn-3.4.4.dist-info/RECORD,,
File without changes