Skip to content

Resolve ${VAR} references in contracts, port as string - #1568

Merged
jochenchrist merged 1 commit into
odcs-3.2.0from
feat/odcs-3.2.0-variables
Sep 2, 2026
Merged

Resolve ${VAR} references in contracts, port as string#1568
jochenchrist merged 1 commit into
odcs-3.2.0from
feat/odcs-3.2.0-variables

Conversation

@jochenchrist

Copy link
Copy Markdown
Contributor

Part of #1559 (#1557). Targets the odcs-3.2.0 branch.

ODCS v3.2.0 (RFC 0050) allows ${VAR_NAME} and ${VAR_NAME:-default} in any string value. Tools must resolve them before use, should error on unresolvable ones, and must preserve them when serializing.

Design

  • Resolved at use time, never on the model. datacontract test resolves the server's fields right after the configuration overrides are applied, and each SQL quality query when the check is prepared. The loaded contract keeps the references, so lint accepts them and export/publish write them back verbatim (covered by a test).
  • One resolver in datacontract/config/variables.py. The config file loader now uses it too and gains the ${VAR:-default} form.
  • Precedence. DATACONTRACT_<SERVER>_<FIELD> overrides still win over the contract. In queries the CLI's own ${model}, ${schema}, ... placeholders are substituted first, so they are not mistaken for variables.
  • Errors. An unset (or empty) variable without a default fails the run with the variable name and the field (server 'prod' host), or fails just that quality check when it is in a query. Never an empty-string substitution.
  • Port. A port holding a reference resolves to an int again; Excel import keeps a ${DB_PORT} cell as a string instead of dropping it.

Tests

Unit tests for the resolver and server resolution, end-to-end DuckDB tests (resolved server and queries, unset server variable, unset query variable, override wins, export keeps references), config file default form, Excel port parsing. Full suite: 2314 passed.

Docs

New "Variables in the data contract" section on the configuration page, a note on the SQL quality rules page (placeholders first, then variables), and a pointer on the testing index.

🤖 Generated with Claude Code

https://claude.ai/code/session_01C1xhK6DjRLWND1ntBcS8fG

ODCS v3.2.0 allows ${VAR} and ${VAR:-default} in any string value.
datacontract test resolves them from the environment when it opens the
connection and when it prepares a SQL quality query, after the CLI's own
${model}-style placeholders. The loaded contract is never mutated, so
lint accepts unresolved references and export writes them back verbatim.

An unset variable without a default fails the run, or the single check,
with the variable's name. Configuration overrides such as
DATACONTRACT_POSTGRES_HOST still win over the contract. The config file
loader shares the resolver and gains the default form. Excel import keeps
a port cell that holds a reference instead of dropping it.
@jochenchrist
jochenchrist merged commit 13757b8 into odcs-3.2.0 Sep 2, 2026
2 checks passed
@jochenchrist
jochenchrist deleted the feat/odcs-3.2.0-variables branch September 2, 2026 16:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant