Repository navigation
dynvar: fix references to resource keys with trailing underscores - #6965
andreamatt wants to merge 1 commit into
Conversation
f6273f9 to
7c49a89
Compare
7c49a89 to
a56a1b0
Compare
|
An authorized user can trigger integration tests manually by following the instructions below: Trigger: Inputs:
Checks will be approved automatically on success. |
andrewnester
left a comment
There was a problem hiding this comment.
Nit: in reference_vectors.json, the pre-existing negative vector segment-trailing-underscore (${hello_world-_.world_world}) now sits next to the new positive trailing-underscore and reads as a contradiction; rename it to segment-trailing-hyphen-underscore?
| // Keep in sync with _base_var_def in python/databricks/bundles/core/_transform.py. | ||
| // Behavioral parity is enforced by testdata/reference_vectors.json. | ||
| const BaseVarDef = `_*\p{L}+([-_]*[\p{L}\p{N}]+)*` | ||
| const BaseVarDef = `_*\p{L}+([-_]*[\p{L}\p{N}]+)*_*` |
There was a problem hiding this comment.
libs/structs/structpath/path.go has a third copy of this grammar (baseVarDef, added in #6980) that still lacks the trailing _*: structpath.PureReferenceToPath("${resources.jobs.job_.id}") returns false while dynvar.IsPureVariableReference returns true. TestPureReferenceMatchesDynvar doesn't catch it because none of its inputs ends a segment with _. Can you update that copy, add a ${var.foo_} case to that test, and list structpath in the keep-in-sync comment above?
| @@ -0,0 +1 @@ | |||
| RecordRequests = false | |||
There was a problem hiding this comment.
With requests not recorded, the output only shows that the deploy didn't fail. If _job__ stopped matching, jobs.ref would still be created, with the literal ${resources.jobs._job__.id} in its name, and this test would pass. Can you record requests and print the jobs/create payloads (as escaped_ref does, with --nostamp so both DMS variants agree) so the resolved name is in output.txt? Or is Created jobs.job_.permissions considered enough here, as in underscore_key_reference?
Changes
Resource keys ending in an underscore (e.g.
my_job_) did not match the reference regex, sobundle plan/deployon the direct engine failed withcannot parse "/jobs/${resources.jobs.my_job_.id}"when planning permissions. User-written${resources.jobs.my_job_.id}references were left unresolved.This is the trailing counterpart of #6422 (leading underscores) and #2203 (double underscores).
Fix: append
_*toBaseVarDefin Go and Python, kept in sync through the sharedreference_vectors.jsonparity test. Only underscores are allowed at the end. The existing negative vectors still hold: trailing hyphens (segment-trailing-hyphen,trailing-hyphen-accent) and a trailing-_(segment-trailing-underscore) still don't match.Why
Terraform accepts these keys, so bundles deployed with the Terraform engine can already contain them. They show up naturally when keys are generated from job names: a job named
[nightly] report (v2)sanitized to[a-zA-Z0-9_-]becomes_nightly__report__v2_.On such bundles:
migration to direct: cannot plan …permissions: cannot parse …, logged only as a warning).Auto-migration of your bundle failed. Install Databricks CLI v1.19.x …).The only workaround today is renaming the key. That deletes and recreates the job, which changes its ID and loses its run history.
Backwards compatibility and previous iterations
The "must end with a letter or digit" rule was a readability choice, not a technical requirement. A segment always ends at
.,[or}, so a trailing_is unambiguous.\w+, somy_job_was accepted. Update variable regex to support hyphens #503 added hyphen support and narrowed segments to "start with a letter, end with a letter or digit". Its description notes this "does break backwards compatibility", and the review says the reason was keeping names human readable.cannot parsefailure on the direct engine.This PR lifts the trailing-underscore part for the same reasons:
${resources.<type>.<key>.id}references forpermissionsandgrantsitself, so it rejects keys the rest of the CLI accepts.The change only widens what matches, so every reference that resolved before still resolves the same way. The one behaviour change: a string like
${foo_}that used to be left as literal text is now treated as a reference, like${_foo}after #6422.$${foo_}still escapes it. Trailing hyphens stay rejected, as the existing vectors require.Tests
libs/dyn/dynvar/testdata/reference_vectors.json:trailing-underscore,resource-key-trailing-underscore,resource-key-leading-and-trailing-underscores.go test ./libs/dyn/...and the Python parity test (databricks_tests/core) pass.acceptance/bundle/resource_deps/trailing_underscore_key_reference, modelled onunderscore_key_reference. Onmainit fails with thecannot parseerror; with this change it deploysjob_with permissions,_job__, and a job referencing both.bundle/schema/jsonschema.jsonregenerated (task generate-schema).go test ./libs/dyn/... ./bundle/config/... ./bundle/schema/... ./bundle/direct/...pass.bundle plan -t devon a bundle with 3 such keys fails onmainand succeeds with this change.