fix: validate instantiated job models with the template's extension context - #362
Open
wyongzhi wants to merge 2 commits into
Open
fix: validate instantiated job models with the template's extension context#362wyongzhi wants to merge 2 commits into
wyongzhi wants to merge 2 commits into
Conversation
…ontext create_job instantiated the target models with a bare constructor, so the FEATURE_BUNDLE_1 length validators on Job.name, Environment.name, EmbeddedFileText.name and EmbeddedFileText.filename ran without a parsing context and fell back to the base limits, rejecting values that decode had already accepted under the extension. instantiate_model now seeds a ModelParsingContext from the root template's declared extensions and constructs each target model with model_validate(..., context=...). Resolved values (the job name) are still checked against the extension-aware limit, matching the schema text and the Rust implementation; literal fields keep the result decode already reached. Models whose class binds no parsing-context type are constructed without a context, exactly as before. The two comments in _model.py that described instantiation as running without a context are updated to match; no validator logic changes. Signed-off-by: Yongzhi Wei <276409147+wyongzhi@users.noreply.github.com>
leongdl
approved these changes
Sep 11, 2026
AlexTranAmz
approved these changes
Sep 11, 2026
seant-aws
approved these changes
Sep 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes: no linked issue (reported directly; see the repro below).
What was the problem/requirement? (What/Why)
create_jobre-validates the models it instantiates, but did so without a parsing context.instantiate_modelbuilt each target model with a baretarget_model(**fields), so inside the models'@field_validatorsinfo.contextwasNone. The FEATURE_BUNDLE_1 length validators introduced in #258 are written as512 if context and "FEATURE_BUNDLE_1" in context.extensions else 128(orelse 64), so with no context they fall back to the base limits and reject values thatdecode_job_templatehad already accepted under the extension:Job.nameEnvironment.nameEmbeddedFileText.nameEmbeddedFileText.filenameRepro (before this change): decode the template below with
supported_extensions=[FEATURE_BUNDLE_1], thencreate_job(job_template=..., job_parameter_values={}).NameIdentifierLengthMixin(#318) already returns early when no context is present, which is why step names and parameter names were unaffected; the four validators above predate that pattern.What was the solution? (How)
instantiate_modelnow seeds one parsing context per call from the root template's declared extensions (model.model_parsing_context_type(supported_extensions=model.extensions or [])) and threads it through the recursion; the final construction becomestarget_model.model_validate(fields, context=context)instead oftarget_model(**fields). Public signature unchanged. The per-fieldTypeAdapter.validate_pythoncalls stay context-free (nothing there readsinfo.context; nested instances are not re-validated). Models that do not bindmodel_parsing_context_type(internal test fixtures) still getcontext=None. The four validators in_model.pyare untouched; two comments there are updated.Why not skip the check when the context is missing:
JobNamelimits apply "after the format string has been resolved" (2023-09 Template Schemas, §1.1.1). A short{{Param.X}}name can resolve to 129+ characters at job creation and must still be rejected without FEATURE_BUNDLE_1; the existingtest_fails_to_instantiate(v0/v1) pins this and passes unchanged. openjd-rs does the same resolved-name re-check at job creation (create_job/mod.rs,create_job_rejects_interpolated_name_exceeding_128_chars). Seeding from the declared extensions matches what decode narrowedcontext.extensionsto.Open question: should the per-field
TypeAdaptercalls receive the same context? Left out since nothing reads it; happy to add for symmetry.What is the impact of this change?
create_job; templates without it behave as before (a 129-char resolved name is still rejected).instantiate_model(exported only fromopenjd.model._internal) directly on a sub-model now validates with an empty extension set rather than none, so mixin-guarded name validators apply the base limit there; the sole in-tree caller passes theJobTemplateroot.How was this change tested?
TestCreateJobPreservesFeatureBundle1Lengthsintest/openjd/model_v0/v2023_09/test_feature_bundle_1.py(30 tests, real decode -> create_job, no mocks):create_job, plus one round trip with all four at the ceiling; together with the resolved 512-char job name below these are the six tests that failed before the fix, with the messages in the table above;{{Param.N}}: 128 accepted / 129 rejected without the extension, 512 accepted / 513 rejected with it;TypeAdapter(JobName), directEnvironment/EmbeddedFileTextconstruction at ceiling + 1);hatch run lintclean;hatch run test: 5825 passed, 24 skipped, 3 xfailed (baseline 5795 passed; +30 new tests).conformance-tests/run_openjd_cli_tests.py, openjd-cli 0.7.7 installed against this checkout):2023-09/FEATURE_BUNDLE_1/jobs/*12 passed / 0 failed (3 Windows-only skipped),2023-09/base/jobs/1.1.1--*3/0,2023-09/FEATURE_BUNDLE_1/job_templates/*41/0, plus the three new substitution fixtures from the companion openjd-specifications PR 3/0; the invalid cases reject with "at most 128" / "at most 512".context=Nonebranch for model classes that bind no parsing-context type is exercised by the existingtest/openjd/model_v0/_internal/test_create_job.py(itsBaseModelForTestingfixtures are revision-agnostic and do not bind one).Companion PR (separate repo, not required for this one): OpenJobDescription/openjd-specifications#184 adds three conformance fixtures that cross the job-name length boundary via parameter substitution. The existing boundary fixtures are all literal names, so the suite did not cover the "after the format string has been resolved" clause.
Was this change documented?
No user-facing documentation change; this restores behaviour the schema already specifies. The two comments in
_model.pythat described instantiation as context-free are updated; docstrings for the changed helpers are updated in_create_job.py.Is this a breaking change?
No. Public API and signatures are unchanged.
Does this change impact security?
No. The change adds a validation context to an in-memory model instantiation; it does not create or modify files, directories, or trust boundaries. No threat model update needed.
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.