Closed robinharms closed 5 months ago
Hi @robinharms, how are you? I didn't get time to work on this. Do you still have this issue?
Given the cost of setup to reproduce the issue, could you please provide me with a toy repository that I could quickly jump into and debug the error?
Sure no problem, I can't do it right away but I'll try to get it done tomorrow!
Here you go! https://github.com/robinharms/pysm-django
Just ask if there's anything else I can do. Thanks a lot for this!
Thanks, @robinharms! I was able to reproduce the issue locally.
Here's what I've found: The root cause of the issue lies in the setUpTestData()
method. Every cls attr created in this method is wrapped in a TestData
class, which performs a deepcopy()
for each test, so this is designed to allow safe alteration of objects between tests on the same TestCase
instance.
However, this conflicts with the creation strategy of state machines. The references of properties/methods used as actions/conditions are computed at the time of creation. So, when the state machine is cloned, the references still point to the original instance.
I'm currently exploring potential solutions to this problem, if any.
Nice! Thanks a lot for this! đŸ˜„
Description
The MachineMixin for Django seems to behave differently when models are used within django tests. Oddly enough, any objects created during setUpTestData seem to cause transitions to bypass checks like conditions.
What I Did
This is a simple django application. Create migrations, run tests. (I'm skipping some imports for stuff you probably know)
statemachines.py
models.py
tests.py
The inner workings of the transitions are still a bit opaque to me, so sorry if there's something obvious I'm missing here.
Thanks for maintaining this great library!