|
2 | 2 |
|
3 | 3 | import copy |
4 | 4 | import re |
| 5 | +import sys |
5 | 6 | from contextlib import suppress |
| 7 | +from types import ModuleType |
6 | 8 | from typing import Any, Callable, Dict, List, Literal, Optional, Tuple, Union, cast |
7 | 9 |
|
8 | 10 | import samtranslator.model.eventsources |
|
34 | 36 | SyncConfigType, |
35 | 37 | UserPoolConfigType, |
36 | 38 | ) |
37 | | -from samtranslator.internal.schema_source import ( |
38 | | - aws_serverless_capacity_provider, |
39 | | - aws_serverless_function, |
40 | | - aws_serverless_graphqlapi, |
41 | | -) |
| 39 | + |
| 40 | +# Pydantic 1 doesn't support Python 3.14 so these imports will fail until we migrate to v2 |
| 41 | +try: |
| 42 | + from samtranslator.internal.schema_source import ( |
| 43 | + aws_serverless_capacity_provider, |
| 44 | + aws_serverless_function, |
| 45 | + aws_serverless_graphqlapi, |
| 46 | + ) |
| 47 | +except RuntimeError: # Pydantic fails when initializing the model classes with a RuntimeError in 3.14 |
| 48 | + aws_serverless_capacity_provider = cast(ModuleType, None) |
| 49 | + aws_serverless_function = cast(ModuleType, None) |
| 50 | + aws_serverless_graphqlapi = cast(ModuleType, None) |
| 51 | + |
42 | 52 | from samtranslator.internal.schema_source.common import PermissionsType, SamIntrinsicable |
43 | 53 | from samtranslator.internal.types import GetManagedPolicyMap |
44 | 54 | from samtranslator.internal.utils.utils import passthrough_value, remove_none_values |
|
143 | 153 | _CONDITION_CHAR_LIMIT = 255 |
144 | 154 |
|
145 | 155 |
|
| 156 | +# Utility function to throw an error when using functionality that doesn't work in Python 3.14 (need migration to Pydantic v2) |
| 157 | +def check_python_314_compatibility(module: Optional[ModuleType], functionality: str) -> None: |
| 158 | + if sys.version_info >= (3, 14) and module is None: |
| 159 | + raise RuntimeError( |
| 160 | + f"{functionality} functionalities are temporarily not supported when running SAM in Python 3.14" |
| 161 | + ) |
| 162 | + |
| 163 | + |
146 | 164 | class SamFunction(SamResourceMacro): |
147 | 165 | """SAM function macro.""" |
148 | 166 |
|
@@ -788,6 +806,7 @@ def _transform_capacity_provider_config(self) -> Dict[str, Any]: |
788 | 806 |
|
789 | 807 | # Validate CapacityProviderConfig using Pydantic model directly for comprehensive error collection |
790 | 808 | try: |
| 809 | + check_python_314_compatibility(aws_serverless_function, "Capacity Provider") |
791 | 810 | validated_model = aws_serverless_function.CapacityProviderConfig.parse_obj(self.CapacityProviderConfig) |
792 | 811 | except Exception as e: |
793 | 812 | raise InvalidResourceException(self.logical_id, f"Invalid CapacityProviderConfig: {e!s}") from e |
@@ -1516,7 +1535,6 @@ class SamCapacityProvider(SamResourceMacro): |
1516 | 1535 | """ |
1517 | 1536 |
|
1518 | 1537 | resource_type = "AWS::Serverless::CapacityProvider" |
1519 | | - resource_property_schema = aws_serverless_capacity_provider.Properties |
1520 | 1538 | property_types = { |
1521 | 1539 | "CapacityProviderName": Property(False, one_of(IS_STR, IS_DICT)), |
1522 | 1540 | "VpcConfig": Property(True, IS_DICT), |
@@ -1549,7 +1567,11 @@ def to_cloudformation(self, **kwargs: Any) -> List[Resource]: |
1549 | 1567 | """ |
1550 | 1568 | Transform the SAM CapacityProvider resource to CloudFormation |
1551 | 1569 | """ |
1552 | | - self.validate_before_transform(schema_class=self.resource_property_schema, collect_all_errors=True) |
| 1570 | + check_python_314_compatibility(aws_serverless_capacity_provider, "Capacity Provider") |
| 1571 | + self.validate_before_transform( |
| 1572 | + schema_class=aws_serverless_capacity_provider.Properties, |
| 1573 | + collect_all_errors=True, |
| 1574 | + ) |
1553 | 1575 |
|
1554 | 1576 | # Use enhanced validation method with comprehensive error collection |
1555 | 1577 | model = self.validate_properties_and_return_model( |
@@ -2657,6 +2679,7 @@ def __init__( |
2657 | 2679 |
|
2658 | 2680 | @cw_timer |
2659 | 2681 | def to_cloudformation(self, **kwargs: Any) -> List[Resource]: |
| 2682 | + check_python_314_compatibility(aws_serverless_graphqlapi, "GraphQLApi") |
2660 | 2683 | model = self.validate_properties_and_return_model(aws_serverless_graphqlapi.Properties) |
2661 | 2684 |
|
2662 | 2685 | appsync_api, cloudwatch_role, auth_connectors = self._construct_appsync_api_resources(model) |
|
0 commit comments