`trans_func` mixin does not handle `AttributeError` when passing in `request`
peterfarrell opened this issue · comments
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)
Cool, thanks for the report. Yes, would certainly accept a PR that fixes this.
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.
@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).
If anyone stumble upon this, you can see the issue we filed with Django FSM Log here:
Thanks for the investigation @peterfarrell