cadwyn 5.4.3__py3-none-any.whl → 5.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.
- cadwyn/schema_generation.py +28 -7
- {cadwyn-5.4.3.dist-info → cadwyn-5.4.4.dist-info}/METADATA +1 -1
- {cadwyn-5.4.3.dist-info → cadwyn-5.4.4.dist-info}/RECORD +6 -6
- {cadwyn-5.4.3.dist-info → cadwyn-5.4.4.dist-info}/WHEEL +0 -0
- {cadwyn-5.4.3.dist-info → cadwyn-5.4.4.dist-info}/entry_points.txt +0 -0
- {cadwyn-5.4.3.dist-info → cadwyn-5.4.4.dist-info}/licenses/LICENSE +0 -0
cadwyn/schema_generation.py
CHANGED
|
@@ -14,6 +14,7 @@ from functools import cache
|
|
|
14
14
|
from typing import (
|
|
15
15
|
TYPE_CHECKING,
|
|
16
16
|
Annotated,
|
|
17
|
+
ClassVar,
|
|
17
18
|
Generic,
|
|
18
19
|
Union,
|
|
19
20
|
_BaseGenericAlias, # pyright: ignore[reportAttributeAccessIssue]
|
|
@@ -41,6 +42,7 @@ from pydantic._internal._decorators import (
|
|
|
41
42
|
from pydantic._internal._known_annotated_metadata import collect_known_metadata
|
|
42
43
|
from pydantic._internal._typing_extra import try_eval_type as pydantic_try_eval_type
|
|
43
44
|
from pydantic.fields import ComputedFieldInfo, FieldInfo
|
|
45
|
+
from pydantic_core import PydanticUndefined
|
|
44
46
|
from typing_extensions import (
|
|
45
47
|
Any,
|
|
46
48
|
Doc,
|
|
@@ -316,7 +318,7 @@ def _wrap_pydantic_model(model: type[_T_PYDANTIC_MODEL]) -> "_PydanticModelWrapp
|
|
|
316
318
|
field_name,
|
|
317
319
|
)
|
|
318
320
|
for field_name in model.__annotations__
|
|
319
|
-
if field_name in defined_fields
|
|
321
|
+
if field_name in defined_fields and field_name in model.model_fields
|
|
320
322
|
}
|
|
321
323
|
|
|
322
324
|
main_attributes = fields | validators
|
|
@@ -592,7 +594,12 @@ class _AnnotationTransformer:
|
|
|
592
594
|
from typing_inspection.typing_objects import is_any, is_newtype, is_typealiastype
|
|
593
595
|
|
|
594
596
|
if isinstance(annotation, (types.GenericAlias, _BaseGenericAlias)):
|
|
595
|
-
|
|
597
|
+
origin = get_origin(annotation)
|
|
598
|
+
args = get_args(annotation)
|
|
599
|
+
# Classvar does not support generic tuple arguments
|
|
600
|
+
if origin is ClassVar:
|
|
601
|
+
return ClassVar[self.change_version_of_annotation(args[0])]
|
|
602
|
+
return origin[tuple(self.change_version_of_annotation(arg) for arg in get_args(annotation))]
|
|
596
603
|
elif is_typealiastype(annotation):
|
|
597
604
|
if (
|
|
598
605
|
annotation.__module__ is not None and (annotation.__module__.startswith("pydantic."))
|
|
@@ -948,11 +955,20 @@ def _add_field_to_model(
|
|
|
948
955
|
f'in "{version_change_name}" but there is already a field with that name.',
|
|
949
956
|
)
|
|
950
957
|
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
958
|
+
# Special handling for ClassVar fields
|
|
959
|
+
if get_origin(alter_schema_instruction.field.annotation) is ClassVar:
|
|
960
|
+
# ClassVar fields should not be in model.fields, only in annotations and other_attributes
|
|
961
|
+
model.annotations[alter_schema_instruction.name] = alter_schema_instruction.field.annotation
|
|
962
|
+
# Set the actual ClassVar value in other_attributes
|
|
963
|
+
if alter_schema_instruction.field.default is not PydanticUndefined:
|
|
964
|
+
model.other_attributes[alter_schema_instruction.name] = alter_schema_instruction.field.default
|
|
965
|
+
else:
|
|
966
|
+
# Regular field handling
|
|
967
|
+
field = PydanticFieldWrapper(
|
|
968
|
+
alter_schema_instruction.field, alter_schema_instruction.field.annotation, alter_schema_instruction.name
|
|
969
|
+
)
|
|
970
|
+
model.fields[alter_schema_instruction.name] = field
|
|
971
|
+
model.annotations[alter_schema_instruction.name] = alter_schema_instruction.field.annotation
|
|
956
972
|
|
|
957
973
|
|
|
958
974
|
def _change_field_in_model(
|
|
@@ -1085,6 +1101,11 @@ def _delete_field_from_model(model: _PydanticModelWrapper, field_name: str, vers
|
|
|
1085
1101
|
validator = model.validators[field_name]
|
|
1086
1102
|
model.validators[field_name].is_deleted = True
|
|
1087
1103
|
model.annotations.pop(field_name, None)
|
|
1104
|
+
elif field_name in model.annotations and get_origin(model.annotations[field_name]) is ClassVar:
|
|
1105
|
+
# Handle ClassVar fields - they exist in annotations but not in model.fields
|
|
1106
|
+
model.annotations.pop(field_name)
|
|
1107
|
+
# Also remove the attribute from other_attributes if it exists there
|
|
1108
|
+
model.other_attributes.pop(field_name, None)
|
|
1088
1109
|
else:
|
|
1089
1110
|
raise InvalidGenerationInstructionError(
|
|
1090
1111
|
f'You tried to delete a field "{field_name}" from "{model.name}" '
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: cadwyn
|
|
3
|
-
Version: 5.4.
|
|
3
|
+
Version: 5.4.4
|
|
4
4
|
Summary: Production-ready community-driven modern Stripe-like API versioning in FastAPI
|
|
5
5
|
Project-URL: Source code, https://github.com/zmievsa/cadwyn
|
|
6
6
|
Project-URL: Documentation, https://docs.cadwyn.dev
|
|
@@ -12,7 +12,7 @@ cadwyn/middleware.py,sha256=4Ziq1ysnc8j5KmeZpsr9VJKllEFC8uYwXnG01I2FPR4,4853
|
|
|
12
12
|
cadwyn/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
13
13
|
cadwyn/route_generation.py,sha256=conoTBtsOtjyiV2NdUxwGQX-h1zLyIjDQjD5bT2YSgg,27185
|
|
14
14
|
cadwyn/routing.py,sha256=Ii6Qbgm9lGks1IAk-kDuIu_dX3FXsA77KSfGOFmLbgc,7604
|
|
15
|
-
cadwyn/schema_generation.py,sha256=
|
|
15
|
+
cadwyn/schema_generation.py,sha256=2_b-PKRma07Rvefpc-bQNNjh3SVFot8ZAtrEgRaI4AY,48848
|
|
16
16
|
cadwyn/_internal/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
17
17
|
cadwyn/_internal/context_vars.py,sha256=VcM8eAoSlvrIMFQhjZmjflV5o1yrPSEZZGkwOK4OSf4,378
|
|
18
18
|
cadwyn/static/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
@@ -24,8 +24,8 @@ cadwyn/structure/endpoints.py,sha256=zUgzglNhBPnmWdJ03A8pFT4zPs_lj8nQ7c7Uo2d-ejU
|
|
|
24
24
|
cadwyn/structure/enums.py,sha256=4FCc9aniLE3VuWAVIacrNP_FWxTIUm9JkeeHA_zZdwQ,1254
|
|
25
25
|
cadwyn/structure/schemas.py,sha256=kuQJg60VpWHZkSPvrbvd9pe-Zetq8as5YYrERsG3IE8,10785
|
|
26
26
|
cadwyn/structure/versions.py,sha256=IrtX8sGswjNc8z_6HsU9Im-U7-agZB_pFaqSHz_0SMk,34710
|
|
27
|
-
cadwyn-5.4.
|
|
28
|
-
cadwyn-5.4.
|
|
29
|
-
cadwyn-5.4.
|
|
30
|
-
cadwyn-5.4.
|
|
31
|
-
cadwyn-5.4.
|
|
27
|
+
cadwyn-5.4.4.dist-info/METADATA,sha256=mkLkjQKFnbx0HCXAWQOywo05HurIxanWa49fg6iHk3k,5076
|
|
28
|
+
cadwyn-5.4.4.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
29
|
+
cadwyn-5.4.4.dist-info/entry_points.txt,sha256=mGX8wl-Xfhpr5M93SUmkykaqinUaYAvW9rtDSX54gx0,47
|
|
30
|
+
cadwyn-5.4.4.dist-info/licenses/LICENSE,sha256=KeCWewiDQYpmSnzF-p_0YpoWiyDcUPaCuG8OWQs4ig4,1072
|
|
31
|
+
cadwyn-5.4.4.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|