Skip to content

fix: allow lazy/translation proxy objects as State/Event name (#632)#636

Merged
fgmacedo merged 2 commits into
developfrom
fix/632-lazy-translation-names
Jun 26, 2026
Merged

fix: allow lazy/translation proxy objects as State/Event name (#632)#636
fgmacedo merged 2 commits into
developfrom
fix/632-lazy-translation-names

Conversation

@fgmacedo

Copy link
Copy Markdown
Owner

Fixes #632.

Problem

Lazy translation strings (e.g. django.utils.translation.gettext_lazy) are proxy objects that are not real str instances, although castable via str(). Changes in 3.x stored a State/Event name as-is and later assumed it was a real str, so a proxy broke:

  • the TransitionNotAllowed message (str.join requires real str elements) — statemachine/exceptions.py;
  • str(state)State.__str__ returned the proxy directly, raising TypeError: __str__ returned non-string.

Fix

Coerce to str at the point of use, keeping the lazy object untouched in storage. Coercing at assignment would resolve the translation at class-definition time, defeating the purpose of i18n (translation must resolve at display time, honoring the active locale).

  • exceptions.py: ", ".join(str(s.name) ...) in the TransitionNotAllowed message.
  • state.py: __str__ returns str(self.name); the hash uses str(self.name) for robust hashability regardless of locale.
  • contrib/diagram/extract.py: coerce names to str once at the domain→model boundary, so every renderer (dot/mermaid/table) receives real str.

Docs

  • Release notes entry in docs/releases/3.2.1.md.
  • Note in docs/states.md that name accepts any object castable to str, resolved at display time.

fgmacedo added 2 commits June 26, 2026 20:52
Signed-off-by: Fernando Macedo <fgmacedo@gmail.com>
Signed-off-by: Fernando Macedo <fgmacedo@gmail.com>
@codecov

codecov Bot commented Jun 26, 2026

Copy link
Copy Markdown

Codecov Report

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

Additional details and impacted files
@@            Coverage Diff            @@
##           develop      #636   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           52        52           
  Lines         5505      5505           
  Branches       869       869           
=========================================
  Hits          5505      5505           
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 Harness.
📢 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 self-assigned this Jun 26, 2026
@fgmacedo fgmacedo added the bug label Jun 26, 2026
@fgmacedo fgmacedo merged commit 471fe17 into develop Jun 26, 2026
13 checks passed
@fgmacedo fgmacedo deleted the fix/632-lazy-translation-names branch June 26, 2026 23:56
@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Please allow translation strings (ie lazy proxy objects) as name

1 participant