Support Python 3.14 / Update Pydantic
Python 3.14 has been released and I've tried running the build.yml workflow but it seems to fail with the following error message:
make pr
shell: /usr/bin/bash -e {0}
env:
pythonLocation: /opt/hostedtoolcache/Python/3.14.0/x64
PKG_CONFIG_PATH: /opt/hostedtoolcache/Python/3.14.0/x64/lib/pkgconfig
Python_ROOT_DIR: /opt/hostedtoolcache/Python/3.14.0/x64
Python2_ROOT_DIR: /opt/hostedtoolcache/Python/3.14.0/x64
Python3_ROOT_DIR: /opt/hostedtoolcache/Python/3.14.0/x64
LD_LIBRARY_PATH: /opt/hostedtoolcache/Python/3.14.0/x64/lib
# Checking latest schema was generated (run `make schema` if this fails)
mkdir -p .tmp
python -m samtranslator.internal.schema_source.schema --sam-schema .tmp/sam.schema.json --cfn-schema schema_source/cloudformation.schema.json --unified-schema .tmp/schema.json
/home/runner/work/serverless-application-model/serverless-application-model/samtranslator/compat.py:2: UserWarning: Core Pydantic V1 functionality isn't compatible with Python 3.14 or greater.
from pydantic import v1 as pydantic
Traceback (most recent call last):
File "<frozen runpy>", line 198, in _run_module_as_main
File "<frozen runpy>", line 88, in _run_code
File "/home/runner/work/serverless-application-model/serverless-application-model/samtranslator/internal/schema_source/schema.py", line 10, in <module>
from samtranslator.internal.schema_source import (
...<10 lines>...
)
File "/home/runner/work/serverless-application-model/serverless-application-model/samtranslator/internal/schema_source/aws_serverless_api.py", line 5, in <module>
from samtranslator.internal.schema_source.aws_serverless_connector import EmbeddedConnector
File "/home/runner/work/serverless-application-model/serverless-application-model/samtranslator/internal/schema_source/aws_serverless_connector.py", line 16, in <module>
class ResourceReference(BaseModel):
...<7 lines>...
Type: Optional[str] = resourcereference("Type")
File "/opt/hostedtoolcache/Python/3.14.0/x64/lib/python3.14/site-packages/pydantic/v1/main.py", line 221, in __new__
inferred = ModelField.infer(
name=var_name,
...<3 lines>...
config=config,
)
File "/opt/hostedtoolcache/Python/3.14.0/x64/lib/python3.14/site-packages/pydantic/v1/fields.py", line 504, in infer
return cls(
name=name,
...<7 lines>...
field_info=field_info,
)
File "/opt/hostedtoolcache/Python/3.14.0/x64/lib/python3.14/site-packages/pydantic/v1/fields.py", line 434, in __init__
self.prepare()
~~~~~~~~~~~~^^
File "/opt/hostedtoolcache/Python/3.14.0/x64/lib/python3.14/site-packages/pydantic/v1/fields.py", line 555, in prepare
self.populate_validators()
~~~~~~~~~~~~~~~~~~~~~~~~^^
File "/opt/hostedtoolcache/Python/3.14.0/x64/lib/python3.14/site-packages/pydantic/v1/fields.py", line 829, in populate_validators
*(get_validators() if get_validators else list(find_validators(self.type_, self.model_config))),
~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/hostedtoolcache/Python/3.14.0/x64/lib/python3.14/site-packages/pydantic/v1/validators.py", line 768, in find_validators
raise RuntimeError(f'no validator found for {type_}, see `arbitrary_types_allowed` in Config')
RuntimeError: no validator found for <class 'pydantic.v1.fields.UndefinedType'>, see `arbitrary_types_allowed` in Config
make: *** [Makefile:37: format-check] Error 1
Error: Process completed with exit code 2.
Pydantic V1 is not compatible with Python 3.14 and greater so I think the serverless-application-model need to update to Pydantic V2.
I believe that this impacts this issue as well on the AWS SAM CLI. Updating the CLI to 3.14 caused this to appear.
Seems like Github's Action runner is on Python 3.14.1. I'm unable to use sam on Github Actions.
sam local invoke --template _/amazon/template.yml --event _/amazon/events/example.com.json node24 2>&1 | (grep 'Error' && exit 1 || exit 0)
shell: /usr/bin/bash -e {0}
env:
pythonLocation: /opt/hostedtoolcache/Python/3.14.1/arm64
PKG_CONFIG_PATH: /opt/hostedtoolcache/Python/3.14.1/arm64/lib/pkgconfig
Python_ROOT_DIR: /opt/hostedtoolcache/Python/3.14.1/arm64
Python2_ROOT_DIR: /opt/hostedtoolcache/Python/3.14.1/arm64
Python3_ROOT_DIR: /opt/hostedtoolcache/Python/3.14.1/arm64
LD_LIBRARY_PATH: /opt/hostedtoolcache/Python/3.14.1/arm64/lib
raise RuntimeError(f'no validator found for {type_}, see `arbitrary_types_allowed` in Config')
RuntimeError: no validator found for <class 'pydantic.v1.fields.UndefinedType'>, see `arbitrary_types_allowed` in Config
Error: Process completed with exit code 1.
Thanks for reporting this and we're sorry we we were not able to look into this sooner. We're working to get this fixed soon.
The migration to Pydantic v2 is more complicated than anticipated. We will make some changes to allow at least partial support for Python3.14 in the meantime, but it's unlikely that we have those changes ready and released before January. Pinning to Python3.13 is the right move for now. We'll have a bigger effort next year to do the proper migration to Pydantic v2.