Skip to content

fix: skip MachineMixin init for Django historical models#561

Merged
fgmacedo merged 1 commit intodevelopfrom
fix/551-machinemixin-django-historical-models
Feb 13, 2026
Merged

fix: skip MachineMixin init for Django historical models#561
fgmacedo merged 1 commit intodevelopfrom
fix/551-machinemixin-django-historical-models

Conversation

@fgmacedo
Copy link
Owner

Summary

  • Django's apps.get_model() creates historical model classes with __module__ = '__fake__' that don't carry user-defined class attributes like state_machine_name
  • MachineMixin.__init__ now detects Django historical models and skips state machine initialization instead of raising ValueError
  • Normal usage is unaffected — the error is still raised when state_machine_name is genuinely missing

Why not deconstruct?

Django's migration serializer uses TypeSerializer for base classes, which serializes by import path only — it never calls deconstruct() on types. That mechanism only applies to field/validator instances.

Closes #551

Django's apps.get_model() creates historical model classes with
__module__ = '__fake__' that don't carry user-defined class attributes
like state_machine_name. Detect this and skip state machine
initialization instead of raising ValueError.

Closes #551
@sonarqubecloud
Copy link

@codecov
Copy link

codecov bot commented Feb 13, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.77%. Comparing base (9697dea) to head (418b36d).
⚠️ Report is 1 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop     #561   +/-   ##
========================================
  Coverage    99.77%   99.77%           
========================================
  Files           25       25           
  Lines         1751     1756    +5     
  Branches       229      230    +1     
========================================
+ Hits          1747     1752    +5     
  Misses           2        2           
  Partials         2        2           
Flag Coverage Δ
unittests 99.77% <100.00%> (+<0.01%) ⬆️

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.

@fgmacedo fgmacedo merged commit 7211235 into develop Feb 13, 2026
15 checks passed
@fgmacedo fgmacedo deleted the fix/551-machinemixin-django-historical-models branch February 13, 2026 19:58
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.

MachineMixin fails in Django migrations with historical models

1 participant

Comments