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

There is no available initial state for the content type #34

Closed
psychok7 opened this issue Oct 14, 2016 · 6 comments
Closed

There is no available initial state for the content type #34

psychok7 opened this issue Oct 14, 2016 · 6 comments

Comments

@psychok7
Copy link
Contributor

@javrasya This issue is somehow related to this one #32

So basically after creating my model with the status = StateField(editable=False) and migrating on an existing DB, i noticed that i had to do a makemigrations/migrate again for it to create an automatic proceeding migration 0007_auto_20161014_1736.
Without this migrations, i would run into this error river.utils.exceptions.RiverException: There is no available initial state for the content type mymodel. With it everything worked fine.

Now i am trying to run a unit test for my rest api endpoint were i have instance = ModelClass.workflow.create(**validated_data) to create a new object, but since i don't have that auto migration i am running into river.utils.exceptions.RiverException: There is no available initial state for the content type mymodel. I tried call_command('makemigrations', stdout=out) and call_command('migrate', stdout=out) from within the test but not luck.

Is there a better way to avoid this error all-together? Or a way for me to force that proceeding extra migration?

Thanks

@javrasya javrasya self-assigned this Oct 15, 2016
@javrasya
Copy link
Owner

javrasya commented Oct 15, 2016

This is happening because you probably didn't define your workflow scenarios yet. I mean, django-river tries to detect initial state in your workflow scenario according to one defined for your model content type and put this initial state into your model instances. This is done by django-river at two different times. Whenever you create a new instance from your model, and whenever you migrate your existing db(contains data) for django-river. You can check 0004_data_fix.py in django-river to see it for second one.
Before doing those, define your workflow scenario(you can use admin interfaces. This is described in video tutorial if you wanna look at)

I should have prepared a tutorial to migrate from existing DB, I see this is the lack of django-river. This is now one of my upcoming plans for django-river :-). Thank you for making me realized that.

If you need more help, let me know please.

@javrasya javrasya removed their assignment Oct 15, 2016
@psychok7
Copy link
Contributor Author

@javrasya oh i see.. since i am running it as a test i probably forgot to create the State, Transition and Proceeding objects to go along my test. When i test it manually everything works because i already have them in my database. I will try that and let you know if it works. Thanks

@psychok7
Copy link
Contributor Author

@javrasya i still haven't figured it out. I tried recreating my admin workflow scenario in my test but still getting the river.utils.exceptions.RiverException: There is no available initial state for the content type qualification request.
basically in my test.py i have

        source_state = State.objects.create(slug='requested', label='requested')
        destination_state = State.objects.create(
            slug='accepted', label='accepted')

        transition = Transition.objects.create(
            source_state=source_state, destination_state=destination_state)

        content_type = ContentType.objects.get_for_model(QualificationRequest)

        proceeding_meta = ProceedingMeta.objects.create(
            content_type=content_type, transition=transition
        )

        out = StringIO()
        sys.stout = out
        call_command('makemigrations', stdout=out)
        print(out.getvalue())
        call_command('migrate', stdout=out)
        print(out.getvalue())
        call_command('showmigrations', stdout=out)
        print(out.getvalue())

        QualificationRequest.workflow.create(
            al_id='35140', name='test', phone='2', email='test@example.com')

What am i doing wrong??

@javrasya
Copy link
Owner

I will try to create a case as same as yours and reproduce it and let you know

@javrasya
Copy link
Owner

javrasya commented Oct 17, 2016

I spotted the problem. This is happenning why you don't give which field you want to create proceeding meta for. I designed django-river to work with multiple state field in a model and it used to work with it. But this was causing a lot of problem about injections and I decided to drop multiple field support. Single state field is supported each model now. But some part of this feature is remanining. I should remove them too I see it now.

Create your proceeding meta by giving field too at the moment. I will remove exactly this field from django-river on next release;

proceeding_meta = ProceedingMeta.objects.create(
            content_type=content_type, transition=transition, field='status'
        )

@psychok7
Copy link
Contributor Author

@javrasya yes the workaround works, thanks.

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

No branches or pull requests

2 participants