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

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

Closed
peterfarrell opened this issue Jul 11, 2016 · 5 comments
Closed

Comments

@peterfarrell
Copy link

peterfarrell commented Jul 11, 2016

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

peterfarrell added a commit to peterfarrell/django-fsm-admin that referenced this issue Jul 11, 2016
@Nagyman
Copy link
Contributor

Nagyman commented Jul 11, 2016

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

@peterfarrell
Copy link
Author

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
Copy link
Author

@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
Copy link
Author

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

jazzband/django-fsm-log#38

@Nagyman
Copy link
Contributor

Nagyman commented Jul 13, 2016

Thanks for the investigation @peterfarrell

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