[BUG]: Operational metadata columns added to target schema when features.operationalMetadataEnabled is false
Is there an existing issue for this?
- [x] I have searched the existing issues
Current Behavior
When a dataflow spec sets features.operationalMetadataEnabled: false, the target table is still created with the operational metadata columns appended to its schema. The source/MV read paths correctly skip adding those columns to the DataFrame, so the table schema and the data written to it no longer match — resulting in null-valued metadata columns or schema-mismatch write failures.
There are three ways to control operational metadata today, but the target schema-init step only honors two of them:
| Control | Where it's set | Honored at target schema init? | Honored at data read / write? |
|---|---|---|---|
TargetConfigFlags.DISABLE_OPERATIONAL_METADATA (per target) |
target.configFlags |
Yes | Yes |
| Pipeline layer not set (no schema loaded) | pipeline_layer empty |
Yes | Yes |
features.operationalMetadataEnabled = false (per dataflow spec) |
dataflow_spec.features |
No | Yes |
The per-spec features flag is not visible to the target at schema-init time because features is constructed later, when the dataflow is assembled — by then the target schema has already been augmented.
CDC snapshot tables are not uniquely affected — they only hit this bug when the feature is disabled at the spec level.
Expected Behavior
When features.operationalMetadataEnabled is false, the target table should be created without operational metadata columns, matching what the source/MV read paths produce. All three controls should behave consistently across schema init and data read/write.
Steps To Reproduce
- Configure a pipeline where
pipeline_layeris set (e.g.silver) so the framework loads an operational metadata schema. - In a dataflow spec, set
features.operationalMetadataEnabled: false. - Define a target with a
schemaPath(any target type — streaming table, MV, staging table, or CDC snapshot). - Run the pipeline and inspect the created target table schema vs. the written data.
Channel
CURRENT
Relevant log output
Suggested fix
Defer the operational-metadata column augmentation out of the target's schema-init step and into create_table(...), where the features object is (or can be made) available. This mirrors the gating already used by the materialized view target.
We built a similar config-driven framework in-house, and I came across your repo while comparing notes on how field engineering solved the same problems. This issue caught my attention, so I traced it through main (v0.23.9) to be sure I understood it.
The bug is seemingly an ordering problem. The metadata columns get added to the table schema when the target object is first built, in BaseTargetDelta._initialize_schema.
But the features flag only shows up later, when create_table is called. So by the time the code could check the flag, the columns are already in the schema. The data side does check the flag, which is why the table and the data end up disagreeing.
The fix you suggested works by adding the columns in create_table instead after checking the flag.
I also checked the places where this could break. The SCD2 and quarantine columns that get added in between are fine, because _add_columns skips columns that already exist. Quarantine tables never had the problem, they are built without a schema file. And the MV target turns out to have the same bug in a milder form, it checks the flag for the data but not for the schema, which this fixes too.
I have it implemented, with unit tests for each combination including the features off, on, absent, and the config flag overriding an enabled features flag.
Here is the draft PR to demonstrate the fix: https://github.com/databricks-solutions/lakeflow_framework/pull/149
Happy to continue pairing on it.