Skip to content
This repository has been archived by the owner on Apr 16, 2024. It is now read-only.

add optional crashed state to the decorator #31

Closed
wants to merge 3 commits into from

Conversation

bacongobbler
Copy link

This adds an optional "crashed" state to the decorator.

When the calling function raises an Exception and the crashed parameter is set in the decorator, the state will change to the crashed state. If the crashed parameter is not set, then the state is unchanged and stays at its original state, which is the old behavior.

This commit is backwards compatible with django-fsm v2.0.1, so all existing users of django-fsm do not have to rewrite their code when this is cut into the next release.

See the tests for an example on how to use this new parameter.

This adds an optional "crashed" state to the decorator.

When the calling function raises an Exception and the crashed
parameter is set in the decorator, the state will change to the
crashed state. If the crashed parameter is not set, then the
state is unchanged and stays at the source state, which is the
original behavior.

This commit is backwards compatible with django-fsm v2.0.1,
so all existing users of django-fsm do not have to rewrite their
code when this is cut into the next release.

See the tests for an example on how to use this new parameter.
@kmmbvnr
Copy link
Collaborator

kmmbvnr commented Apr 11, 2014

Thanks for additions!

Could you also modify graph_transition command, and add different styled edges points to new crashed states?

Also please include new functionallity description into Readme.

self.set_state(instance, meta.exception_state(current_state))
raise
finally:
post_transition.send(**signal_kwargs)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is the problem. signal_kwargs contains initial target state, but actually transition to crashed state happens.

@bacongobbler
Copy link
Author

The signal_kwargs issue that you commented on wasn't caught in the test suite.. should that be caught? Not sure how to write out a test for that, as Django signals and the like are new to me.

I will be happy to add a patch to the README to explain the new usage, but I don't know the first thing about pygraphvis. I'd be happy to implement it if you showed me what I need to do, however.

signal_kwargs contains the initial target state, but if an
exception is caught, it transitions to the crashed state. This
commit reflects that behavior.
@kmmbvnr
Copy link
Collaborator

kmmbvnr commented Apr 11, 2014

I think Transition tuple should be extended with crashed states and this state should be added as new vertex to the graph. This new vertex could be connected to source vertex with edge with dotted style

So, something like that need to be added to output: "souce" -> "crashed" [style="dotted"];

Dot format pretty fine described here:
http://en.wikipedia.org/wiki/DOT_(graph_description_language)

Also you could just run graph_transition command to see what kind of text created now.

if the decorated function raised an exception, result would never
be set.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants