Bind a named version to specific data and feature semantics, and refuse a conflicting reuse of that identity.
Problem
When you need this. A model file cannot explain its inputs if a name such as events-v1 can later refer to different bytes. The user-return application needs to retain the selected dataset and the feature definition that gives those bytes meaning.
This workshop adapts the existing version-binding pattern. It records the feature contract and hashes the shared scenario and the implementation files that prepare the training data. A local SQLite registry binds the dataset and feature identities in one transaction.
Concepts
A dataset digest identifies exact bytes. The feature contract describes the one-day count, strict event and arrival cutoffs, feature order and supported value range. The implementation hashes bind the code that interprets that contract.
A version name claims that one meaning stays fixed. The registry refuses to reuse version 1 for a changed two-day window. Creating a new version records a different meaning; it does not make the new feature compatible with a model trained on the old one.
The contract ID is a hash of the captured manifest, so identical retries produce the same ID. The registry writes the dataset and feature bindings in one SQLite transaction. If either one conflicts, the transaction rolls back, and no half-written dataset/feature binding remains.
A hash shows that an input differs from an expected identity. It does not show who produced the input, whether the data is correct or whether a feature is useful. This lab assumes a trusted local workspace and does not authenticate where inputs come from.
Architecture
Working code
Download the shared application and tests, unzip it and enter mlops-return-workflow/. Keep the same directory throughout the course. Create the environment once. This workshop uses the standard library.
python3.12 -m venv .venv
source .venv/bin/activateOn PowerShell, activate with .venv\Scripts\Activate.ps1.
Capture and bind the application contract
The command records the current source and shared fixture, binds version 1, and deliberately attempts to reuse that version with a changed feature window. It then retries the original binding.
def contract(source):
files={name:w.sha(HERE/name) for name in CORE_FILES if name!='scenario.json'}
return {'project':w.PROJECT,'format':'return-application-contract-v1',
'dataset_sha256':w.sha(source),'feature':FEATURE_CONTRACT,'implementation':files}def bind_contract(database, manifest, version=1):
if type(version) is not int or version<1:raise ValueError('version must be a positive integer')
path=Path(database);path.parent.mkdir(parents=True,exist_ok=True)
components={'dataset':manifest['dataset_sha256'],'feature':digest({'definition':manifest['feature'],'implementation':manifest['implementation']})}
with sqlite3.connect(path) as db:
db.execute('CREATE TABLE IF NOT EXISTS identities (kind TEXT,project TEXT,version INTEGER,digest TEXT,PRIMARY KEY(kind,project,version))')
for kind,value in components.items():
old=db.execute('SELECT digest FROM identities WHERE kind=? AND project=? AND version=?',(kind,w.PROJECT,version)).fetchone()
if old and old[0]!=value:raise ValueError('version already means different '+kind)
db.execute('INSERT OR IGNORE INTO identities VALUES (?,?,?,?)',(kind,w.PROJECT,version,value))
return {'version':version,'contract_id':digest(manifest),'components':components}python adapt.py versioning --work work/adaptations{
"bound": {
"version": 1,
"contract_id": "c5949d7b20bb578e0e641aec284179b3c36cf54e6fdbc3862760439b6214905f",
"components": {
"dataset": "5d009da4b520ee466b7919ab6d3bd5507c5d6c0e56be4d64302bb1ee9c347619",
"feature": "34aa781f9170e1133984d58e82050aa8bc545728df9b217001720220018acedd"
}
},
"changed_definition_refused": "version already means different feature",
"identical_retry_id": "c5949d7b20bb578e0e641aec284179b3c36cf54e6fdbc3862760439b6214905f"
}The registry refuses the changed definition, and the identical retry returns the same contract ID. The full application-contract.json remains in the work directory so that later training runs can retain the same selected identities.
The output above comes from a saved local Python/SQLite run in recorded-adaptations/; your commands write to work/. Read the actual command records. Use a fresh work directory for another attempt.
Failure cases
Run test_same_version_cannot_change_meaning and test_failed_binding_rolls_back_all_new_components. They exercise identity conflicts and transaction rollback against the actual registry. The rollback test removes the stored dataset row, then binds a manifest whose new dataset inserts first and whose feature conflicts. After the failure, the registry still has no dataset row.
Anyone who can write to the registry can still bind a new version to poor-quality data. Versioning helps you reproduce and review a run; it does not validate data or evaluate a model.
python -m unittest -v test_workflow.py test_foundations.pyRunning and scaling the workshop
The registry is a local SQLite file on one machine. It has no access control and is not a shared registry.
For a larger dataset, store immutable snapshots in an appropriate object store and retain their expected identities. Hashing a mutable file and reopening it later can create a time-of-check/time-of-use gap: the file can change between the hash and the read. The next tracking workshop copies a selected source snapshot for execution.
Key takeaways
- Version the data and the rules that turn it into model input.
- An identity conflict must fail instead of silently replacing the old meaning.
- A new feature version needs an explicit model-compatibility decision.
Best practices
Keep version binding and data-quality approval separate.
Create a new version when the feature definition or any of its implementation files changes; the feature digest covers both.
When the registry refuses a binding, choose a new version number and review model compatibility. Do not delete the stored row to make the old number fit.
Retain the actual source snapshot used by a training run rather than relying on a branch name alone.
Check your understanding
Does changing only the version number make a two-day count compatible with the saved one-day model?
Show the explanation
No. The model expects a specific feature definition and fitted preprocessing. A different window needs its own evaluation and an explicit compatible model release.
Read the explanation
The existing feature version is bound to its original definition. A two-day window needs a new version and a model-compatibility decision.