Bug Summary
When an EDA project's scm_branch is updated to a different Git tag (e.g. v1.0.0 to v1.1.0) and the project is synced, existing rulebook activations with event stream source mappings cannot be restarted. The API returns:
{'source_mappings': 'Rulebook has changed since the sources were mapped. Please reattach event streams'}
The root cause is that _sync_rulebook() in services/project/imports.py updates Rulebook.rulesets and Activation.rulebook_rulesets but never updates the rulebook_hash embedded inside Activation.source_mappings. The stale hash then fails the comparison in _validate_sources_with_event_streams().
Environment
Steps to reproduce
- Create an EDA project pointing to a Git repo at tag
v1.0.0
- Create an event stream
- Create a rulebook activation using a rulebook from that project, with event stream source mappings attached (the API stores a
rulebook_hash inside source_mappings)
- Confirm the activation runs successfully
- Update the EDA project's
scm_branch from v1.0.0 to v1.1.0 (where the rulebook file has any text change, even a comment or whitespace)
- Sync the project
- Attempt to restart the activation
Actual results
Restart fails with HTTP 400:
{"errors": "{'source_mappings': 'Rulebook has changed since the sources were mapped. Please reattach event streams'}"}
The activation is set to error state. The user must manually edit the activation and re-attach event streams, even when the source definitions are functionally identical.
Expected results
When a project sync updates a rulebook's content, the rulebook_hash stored inside source_mappings on affected activations should be updated to match. Restart and enable operations should continue to work without manual re-attachment when the sources are structurally unchanged.
Additional information
Root cause spans two code paths:
-
src/aap_eda/services/project/imports.py, _sync_rulebook(): updates rulebook.rulesets and Activation.rulebook_rulesets via bulk update(), but does not touch Activation.source_mappings.
-
src/aap_eda/api/serializers/activation.py, _validate_sources_with_event_streams(): recomputes get_rulebook_hash(rulebook.rulesets) and compares it against the now-stale rulebook_hash in source_mappings.
Proposed fix: In _sync_rulebook(), when the content has changed, iterate over affected activations and rewrite the rulebook_hash inside each source_mappings entry to match the new hash. A draft patch is available.
Bug Summary
When an EDA project's
scm_branchis updated to a different Git tag (e.g.v1.0.0tov1.1.0) and the project is synced, existing rulebook activations with event stream source mappings cannot be restarted. The API returns:The root cause is that
_sync_rulebook()inservices/project/imports.pyupdatesRulebook.rulesetsandActivation.rulebook_rulesetsbut never updates therulebook_hashembedded insideActivation.source_mappings. The stale hash then fails the comparison in_validate_sources_with_event_streams().Environment
mainbranch)Steps to reproduce
v1.0.0rulebook_hashinsidesource_mappings)scm_branchfromv1.0.0tov1.1.0(where the rulebook file has any text change, even a comment or whitespace)Actual results
Restart fails with HTTP 400:
{"errors": "{'source_mappings': 'Rulebook has changed since the sources were mapped. Please reattach event streams'}"}The activation is set to
errorstate. The user must manually edit the activation and re-attach event streams, even when the source definitions are functionally identical.Expected results
When a project sync updates a rulebook's content, the
rulebook_hashstored insidesource_mappingson affected activations should be updated to match. Restart and enable operations should continue to work without manual re-attachment when the sources are structurally unchanged.Additional information
Root cause spans two code paths:
src/aap_eda/services/project/imports.py,_sync_rulebook(): updatesrulebook.rulesetsandActivation.rulebook_rulesetsvia bulkupdate(), but does not touchActivation.source_mappings.src/aap_eda/api/serializers/activation.py,_validate_sources_with_event_streams(): recomputesget_rulebook_hash(rulebook.rulesets)and compares it against the now-stalerulebook_hashinsource_mappings.Proposed fix: In
_sync_rulebook(), when the content has changed, iterate over affected activations and rewrite therulebook_hashinside eachsource_mappingsentry to match the new hash. A draft patch is available.