Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log transitions #27

Closed
Blackeagle52 opened this issue Oct 23, 2012 · 7 comments
Closed

Log transitions #27

Blackeagle52 opened this issue Oct 23, 2012 · 7 comments

Comments

@Blackeagle52
Copy link

I am new to your product and I don't know if this is a issue within the documentation, my know-how of django or something else.

I am creating a class Process, which is a StateModel. Within this class I have a subclass, Machine(StateMachine). Within this class log_transitions is default True. See code below as current situation.

class Process(StateModel):
    applicant = models.IntegerField(null=True, blank=True,
        verbose_name=_("applicant"))

    class Meta:
        app_label = 'testing_process'
        verbose_name = _('process')
        verbose_name_plural = _('processes')

    class Machine(StateMachine):
        # possible states
        class initiated(StateDefinition):
            description = _('process initiated')
            initial = True

        class process_started(StateDefinition):
            description = _('process started')

        #state transitions
        class request_offer(StateTransition):
            from_state = "initiated"
            to_state = "process_started"
            description = _("Start up the process")

I am testing this class with the following lines

from testing_process.models.process import Process
proc, c = Process.objects.get_or_create(applicant=1)
proc.make_transition('request_offer')

I get the following error; DatabaseError:
(1146, "Table 'testing_process.models_processstatelog' doesn't exist")

But when with syncdb the table isn't created. It isn't either shown with sqlall. States2 is in my requirements.txt, placed within my setting in INSTALLED_APPS. I solved it temporary with log_transitions = False, but I ofcourse want to log my transitions.

@jonathanslenders
Copy link
Contributor

Hi Blackeagle52, I guess the problem is in your app_label.

Are you defining the model Process in another Django module than testing_process? I guess your Process model is registered in the correct place, but the ProcessStateTransition model (which is dynamically generated), does not know that it should be registered in testing_process. Try adding the module where process is defined in, to the INSTALLED_APPS.

If that's the case, I can easily write a patch for that. (but feel free to do it yourself.

@Blackeagle52
Copy link
Author

Nope, in my project there is only one model called Process, and it can be found in the module test_process. And this module is also already added to INSTALLED_APPS.

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.admin',
    '<appname>.testing_process',
    'states2',
    )

Syncdb did create a Process table, with a field state, maybe I should mention this sooner.

states2 works because of -e git+https://github.com/citylive/django-states2.git#egg=states2 in my requirements.txt.

@jonathanslenders
Copy link
Contributor

Your module is testing-process, while your app is test-process. It's best to be consistent. Is it working when you rename your python module?

It is a bug nontheless (that the app label in the meta is not passed to the logging model) which I will fix asap. But I'm just wondering whether this is the cause and the above answer will resolve your issue.

Cheers,
Jonathan

@Blackeagle52
Copy link
Author

Sorry, my module is also testing_process, I made a typing error in the explanation. I am looking forward to the fix.

@jonathanslenders
Copy link
Contributor

Can you check out the latest commit on the master branch of states2? It's this change:
75cd5d4

I did a test in my local setup, and it seemed to fix the issue. If it doesn't work, can you somehow create a zip file of your test project, and mail it to jonathan.slenders@mobilevikings.com

@Blackeagle52
Copy link
Author

Had a day off, so sorry for the delay, but I have good news;

Creating tables ...
Creating table testing_process_processstatelog
Installing custom SQL ...

Also the test succeeded. Thank you for your fast assistance!

@jonathanslenders
Copy link
Contributor

You're welcome!

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

No branches or pull requests

2 participants