Skip to content

fix: Configuration.add()/discard() write through model setter for persistence#596

Merged
fgmacedo merged 1 commit intodevelopfrom
macedo/model-persistence-fix
Mar 11, 2026
Merged

fix: Configuration.add()/discard() write through model setter for persistence#596
fgmacedo merged 1 commit intodevelopfrom
macedo/model-persistence-fix

Conversation

@fgmacedo
Copy link
Owner

In-place mutation of the OrderedSet returned by self.value lost state changes when the model uses a deserializing property (e.g., Django model field backed by a DB column). Each getter call returned a fresh object, the in-place mutation modified a temporary, and the model was never updated.

Changed add() and discard() to create a new OrderedSet and assign via self.value = new, which calls setattr on the model. This only affects atomic_configuration_update=False (StateChart default); the atomic path was never affected.

Benchmark impact: ~4-5% on parallel region events (~2µs per event), negligible vs. callback execution in the same microstep.

…sistence

In-place mutation of the OrderedSet returned by self.value lost state changes
when the model uses a deserializing property (e.g., Django model field backed
by a DB column). Each getter call returned a fresh object, the in-place
mutation modified a temporary, and the model was never updated.

Changed add() and discard() to create a new OrderedSet and assign via
self.value = new, which calls setattr on the model. This only affects
atomic_configuration_update=False (StateChart default); the atomic path
was never affected.

Benchmark impact: ~4-5% on parallel region events (~2µs per event),
negligible vs. callback execution in the same microstep.

Signed-off-by: Fernando Macedo <fernando.macedo@jusbrasil.com.br>
@sonarqubecloud
Copy link

sonarqubecloud bot commented Mar 11, 2026

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarQube Cloud

@fgmacedo fgmacedo merged commit cd05c6e into develop Mar 11, 2026
12 checks passed
@fgmacedo fgmacedo deleted the macedo/model-persistence-fix branch March 11, 2026 01:56
@codecov
Copy link

codecov bot commented Mar 11, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (2476d20) to head (267eaf3).
⚠️ Report is 1 commits behind head on develop.

Additional details and impacted files
@@            Coverage Diff            @@
##           develop      #596   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           42        42           
  Lines         5007      5008    +1     
  Branches       813       813           
=========================================
+ Hits          5007      5008    +1     
Flag Coverage Δ
unittests 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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