Breaking Changes
Error Handling Changes
- Additional imports are now validated as Python import paths - Values passed via
--additional-imports, the Python config API (GenerateConfig,JSONSchemaParserConfig, etc.), or--extra-template-datamust now be dotted sequences of Python identifiers. Previously any value was accepted and split on commas without validation; now inputs that are not valid import paths (e.g. containing newlines, semicolons, or non-identifier syntax) raise anErrorand abort generation instead of being emitted into the generated output. Valid dotted paths (optionally whitespace-padded) continue to work unchanged. (#3763)
additional_imports must be a Python import path composed of identifiers: 'collections.deque\nINJECTION_MARKER = 1'
Default Behavior Changes
- Reserved template keys in
--extra-template-datanow raise an error for built-in templates - When rendering a built-in (project-owned) template, supplying any generator-reserved key through--extra-template-data(or theextra_template_dataAPI argument) now raises anErrorand aborts generation instead of injecting the value. The reserved keys areclass_body_lines,config_items,schema_runtime_validation,schema_runtime_validation_base_class_name,schema_runtime_validation_use_base,sequence_base_class,sequence_item_type,sequence_slice_type,_safe_config_items,typed_dict_kwargs, andtyped_dict_kwargs_suffix. To inject raw code via these keys you must now use a custom root template through--custom-template-dir. (#3765) - Stricter
extra_template_datavalidation -extra_template_datathat is not a dictionary, contains non-string keys, or contains duplicate (normalized) keys now raises anErrorrather than being silently accepted. (#3765)
Code Generation Changes
- Built-in templates now serialize
extra_template_datavalues as non-executing literals - For built-in templates, user-supplied values that were previously emitted as raw Python source are now serialized as quoted, non-executing literals. This affects GraphQL scalarpy_type, TypedDictadditionalPropertiesType,ConfigDictvalues, msgspecbase_class_kwargs, and comments. Only bare or dotted identifiers (e.g.datetime.date) are still emitted unquoted; more complex expressions become string literals. For example, a scalarpy_typesupplied as a type expression is now rendered as:
Evil = TypeAliasType("Evil", "__import__('os').system('id') or str")Trusted custom root templates (--custom-template-dir providing the root template) keep the previous unrestricted raw behavior. (#3765)
- Include-only custom template directories no longer receive raw built-in context - "Custom root" detection changed from
template_file_path.is_absolute()to_uses_custom_root_template. A--custom-template-dirthat only supplies include/partial templates (not the model's root template) no longer opts the built-in root into the unrestricted raw-context path; itsextra_template_datais now treated with the hardened built-in rules (and reserved keys raise an error). (#3765)
What's Changed
- Update CHANGELOG for 0.72.4 by @dcg-generated-docs[bot] in #3736
- Update release benchmark data by @dcg-generated-docs[bot] in #3737
- Guard refactor contracts by @koxudaxi in #3739
- Tighten generation types by @koxudaxi in #3740
- Simplify generation dispatch by @koxudaxi in #3741
- Simplify parser metadata flow by @koxudaxi in #3742
- Optimize built-in generation performance by @koxudaxi in #3738
- Optimize simple field construction by @koxudaxi in #3754
- Optimize msgspec unset field rendering by @koxudaxi in #3755
- Optimize false reference handling by @koxudaxi in #3750
- Compile built-in templates by @koxudaxi in #3757
- Optimize Pydantic field name resolution by @koxudaxi in #3758
- Avoid Jinja in the playground runtime by @koxudaxi in #3759
- Fix main lint workflow by @koxudaxi in #3761
- Bump the github-actions group with 5 updates by @dependabot[bot] in #3751
- Fix payload runtime validation exclusions by @koxudaxi in #3764
- Validate additional import paths by @koxudaxi in #3763
- Harden built-in template data by @koxudaxi in #3765
- Restrict template source paths by @koxudaxi in #3766
Full Changelog: 0.72.4...0.73.0