toladata / TolaActivity

Workflow, visualizations and data services for managing NGO projects and programs
11 stars 20 forks source link

Cannot delete WorkflowTeam that has no role #1120

Open rafa-munoz opened 6 years ago

rafa-munoz commented 6 years ago

Current behavior

When a WorkflowTeam instance is deleted and it has no role assigned, it's raising an exception. Making it impossible to getting deleted:

ERROR:django.request:Internal Server Error: /admin/workflow/workflowteam/11/delete/
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/usr/local/lib/python2.7/site-packages/django/utils/decorators.py", line 67, in _wrapper
  File "/usr/local/lib/python2.7/site-packages/django/utils/decorators.py", line 63, in bound_func
  File "/usr/local/lib/python2.7/site-packages/django/db/models/deletion.py", line 279, in delete
    sender=model, instance=obj, using=self.using
    if count == 1 and instance.role.name in [ROLE_PROGRAM_ADMIN,
  File "/usr/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 185, in _get_response
    response = view_func(request, *args, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/django/views/decorators/cache.py", line 57, in _wrapped_view_func
  File "/usr/local/lib/python2.7/site-packages/django/utils/decorators.py", line 149, in _wrapped_view
    return collector.delete()
AttributeError: 'NoneType' object has no attribute 'name'
    response = self.process_exception_by_middleware(e, request)
  File "/usr/local/lib/python2.7/site-packages/django/contrib/admin/sites.py", line 224, in inner
    return view(request, *args, **kwargs)
    response = view_func(request, *args, **kwargs)
    self.delete_model(request, obj)
  File "/usr/local/lib/python2.7/site-packages/django/contrib/admin/options.py", line 985, in delete_model
  File "/usr/local/lib/python2.7/site-packages/django/dispatch/dispatcher.py", line 193, in send
Traceback (most recent call last):
    response = get_response(request)
  File "/usr/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 187, in _get_response
  File "/usr/local/lib/python2.7/site-packages/django/contrib/admin/options.py", line 551, in wrapper
  File "/usr/local/lib/python2.7/site-packages/django/utils/decorators.py", line 149, in _wrapped_view
    return bound_func(*args, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/django/contrib/admin/options.py", line 1723, in _delete_view
    obj.delete()
  File "/usr/local/lib/python2.7/site-packages/workflow/signals.py", line 229, in check_seats_delete_team
  File "/usr/local/lib/python2.7/site-packages/django/core/handlers/exception.py", line 41, in inner
    response = view_func(request, *args, **kwargs)
    return func.__get__(self, type(self))(*args2, **kwargs2)
  File "/usr/local/lib/python2.7/site-packages/django/contrib/admin/options.py", line 1690, in delete_view
    return self._delete_view(request, object_id, extra_context)
  File "/usr/local/lib/python2.7/site-packages/django/db/models/base.py", line 973, in delete
    for receiver in self._live_receivers(sender)
    return self.admin_site.admin_view(view)(*args, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/django/utils/decorators.py", line 149, in _wrapped_view
  File "/usr/local/lib/python2.7/site-packages/django/contrib/admin/options.py", line 1690, in delete_view
  File "/usr/local/lib/python2.7/site-packages/django/db/models/base.py", line 973, in delete
    for receiver in self._live_receivers(sender)
  File "/usr/local/lib/python2.7/site-packages/django/contrib/admin/sites.py", line 224, in inner
    return func.__get__(self, type(self))(*args2, **kwargs2)
  File "/usr/local/lib/python2.7/site-packages/django/contrib/admin/options.py", line 1723, in _delete_view
    obj.delete()
    return collector.delete()
  File "/usr/local/lib/python2.7/site-packages/django/db/models/deletion.py", line 279, in delete
    response = get_response(request)
    response = self.process_exception_by_middleware(e, request)
    response = view_func(request, *args, **kwargs)
    response = view_func(request, *args, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/django/contrib/admin/options.py", line 985, in delete_model
    sender=model, instance=obj, using=self.using
AttributeError: 'NoneType' object has no attribute 'name'

The error comes from check_seats_delete_team() if count == 1 and instance.role.name in [ROLE_PROGRAM_ADMIN,

Acceptance criteria

GIVEN I am the admin AND I try to delete a WorkflowTeam without a role THEN the deletion should be done