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

fsm_log_by decorator does not persist by #69

Closed
jlost opened this issue Feb 7, 2018 · 1 comment
Closed

fsm_log_by decorator does not persist by #69

jlost opened this issue Feb 7, 2018 · 1 comment

Comments

@jlost
Copy link

jlost commented Feb 7, 2018

model:

@fsm_log_by
@transition(field=status, source=Status.PENDING_CODE_REVIEW.name, target=Status.CODE_REJECTED.name)
def reject_code(self, by=None):
        print('REJECTING...')
        print(by.id)
        pass

(Successfully prints user's id but doesn't persist by to StateLog)

views.py:

def post(self, request, job_id):
     job = get_object_or_404(Job, pk=job_id)
     if not can_proceed(job.reject_code):
          raise PermissionDenied
     job.reject_code(self.request.user)
     job.save()

DB:

postgres=# select * from django_fsm_log_statelog;
 id |           timestamp           |     state     |  transition  | object_id | by_id | content_type_id
----+-------------------------------+---------------+--------------+-----------+-------+-----------------
  1 | 2018-02-06 14:40:30.159429+00 | QUEUED        | approve_code |         2 |       |               1
  2 | 2018-02-06 14:58:45.591487+00 | DELETED       | delete       |         1 |       |               1
  3 | 2018-02-06 15:28:10.691508+00 | QUEUED        | approve_code |         3 |       |               1
  4 | 2018-02-07 14:08:30.8747+00   | CODE_REJECTED | reject_code  |         4 |       |               1
  5 | 2018-02-07 14:09:42.174577+00 | CODE_REJECTED | reject_code  |         5 |       |               1
  6 | 2018-02-07 14:32:12.451424+00 | CODE_REJECTED | reject_code  |         6 |       |               1
(6 rows)

REPL:

>>> StateLog.objects.get(pk=6).by
>>> StateLog.objects.get(pk=6).by_id

This is with the latest pip release, 1.5.0

@jlost jlost changed the title by decorator not working fsm_log_by decorator does not persist by Feb 7, 2018
@jlost
Copy link
Author

jlost commented Feb 7, 2018

Found my obvious rookie mistake -- passing in the user as an arg rather than kwarg.

Fix: job.reject_code(self.request.user) -> job.reject_code(by=self.request.user)

@jlost jlost closed this as completed Feb 7, 2018
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

1 participant