zzgvh / django-workflows

Fork of https://bitbucket.org/diefenbach/django-workflows
BSD 3-Clause "New" or "Revised" License
5 stars 3 forks source link

remove_workflow_from_object Performs Query Incorrectly #1

Open davydany opened 13 years ago

davydany commented 13 years ago

When I call remove_workflow() from workflows.utils and pass my object, it throws a WorkflowObjectRelation.DoesNotExist error.

When I looked into the code, this line performs the query incorrectly: https://github.com/zzgvh/django-workflows/blob/master/workflows/utils.py#L99 ContentTypes relations don't get queried in that manner. And since the exception that it throws is not being reported, there are "ghost" entries in the WorkflowObjectRelation table.

Should be something along the lines of:


    WorkflowObjectRelations.objects.get(content_type = ctype, object_id = obj.pk)
davydany commented 13 years ago

I modified it like this locally until this fixed.


def remove_workflow_from_object(obj):
    app_label = obj._meta.app_label
    model_name = obj.__class__.__name__

    ctype = ContentType.objects.get(app_label = app_label, model = model_name)
    try:
        wor = WorkflowObjectRelation.objects.get(content_type = ctype, content_id = obj.pk)
    except WorkflowObjectRelation.DoesNotExist:
        pass
    else:
        wor.delete()

    reset(obj)
    set_initial_state(obj)