gadventures / django-fsm-admin

Mixin and template tags to integrate django-fsm transitions into the django admin.
Other
203 stars 95 forks source link

`trans_func` mixin does not handle `AttributeError` when passing in `request` #56

Closed peterfarrell closed 8 years ago

peterfarrell commented 8 years ago

When using Django FSM Admin with Django FSM Log on Python 3.4, the call to trans_func(request=request, by=request.user) fails with an AttributeError on the the kwarg request and the try/except is only looking for TypeError. The error reads as follows where my_transition is the name of the transition method:

my_transition() got an unexpected keyword argument 'request'

It appears that if we remove the @fsm_log_by decorator then everything works. This is strange because we have several other transitions that have logging that works.

From https://github.com/gadventures/django-fsm-admin/blob/master/fsm_admin/mixins.py#L162-L172

            try:
                # Attempt to pass in the request and by argument if using django-fsm-log
                trans_func(request=request, by=request.user)
            except TypeError:
                try:
                    # Attempt to pass in the by argument if using django-fsm-log
                    trans_func(by=request.user)
                except TypeError:
                    # If the function does not have a by attribute, just call with no arguments
                    trans_func()
            new_state = self.display_fsm_field(obj, fsm_field_name)

screen shot 2016-07-11 at 11 52 27 am

Nagyman commented 8 years ago

Cool, thanks for the report. Yes, would certainly accept a PR that fixes this.

peterfarrell commented 8 years ago

I tried a patch where however then we get a transition not allowed error:

https://github.com/peterfarrell/django-fsm-admin/tree/peterfarrell-patch-56

The error goes away if we take out the @fsm_log_by decorator. We have other transitions setup exactly the same way with the log by decorate that work just fine. So I am suspecting that the issue lies in the the logging package for FSM.

peterfarrell commented 8 years ago

@Nagyman Closing this issue. We discovered it has to do with the why Django FSM Log's decorate deleted the by kwarg prematurely when calling a transition from another transition in the same object. We will file an issue with that project (and a patch).

peterfarrell commented 8 years ago

If anyone stumble upon this, you can see the issue we filed with Django FSM Log here:

https://github.com/gizmag/django-fsm-log/issues/38

Nagyman commented 8 years ago

Thanks for the investigation @peterfarrell