/api/workers/availabilities/ called instead of /api/daily_planning/workers/availabilities/
Somehow there are records in the server logs that show a call like /api/workers/availabilities/
to the api url
url(r'^workers/(?P<worker_role>[A-z]+)/$', worker.get_workers, name='web.api.workers')
instead of the api url
url(r'^daily_planning/workers/availabilities$', worker.availabilities, name='web.api.workers.daily_planning.availabilities$')
I tried to look for it but I can't find where is happening.
The error shown in the logs is:
ERROR 2018-12-03 14:32:11,355 exception 31256 140076898141952 Internal Server Error: /api/workers/availabilities/
Traceback (most recent call last):
File "/var/www/scheduling-system/env/local/lib/python2.7/site-packages/django/core/handlers/exception.py", line 41, in inner
response = get_response(request)
File "/var/www/scheduling-system/env/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 187, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/var/www/scheduling-system/env/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 185, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/var/www/scheduling-system/smash/web/api_views/worker.py", line 75, in get_workers
all_workers = Worker.get_workers_by_worker_type(worker_role).distinct()
File "/var/www/scheduling-system/smash/web/models/worker.py", line 260, in get_workers_by_worker_type
roles__role__in=roles_by_worker_type(worker_type))
File "/var/www/scheduling-system/smash/web/models/worker.py", line 26, in roles_by_worker_type
role_choices = role_choices_by_worker_type(worker_type)
File "/var/www/scheduling-system/smash/web/models/worker.py", line 42, in role_choices_by_worker_type
raise TypeError("Unknown worker type")
TypeError: Unknown worker type
At the moment, to control this exception I propose to add the following try catch to avoid the execption:
def roles_by_worker_type(worker_type):
try:
role_choices = role_choices_by_worker_type(worker_type)
except TypeError:
role_choices = []
roles = []
for role_type, role_name in role_choices:
roles.append(role_type)
return roles
def role_choices_by_worker_type(worker_type):
if worker_type == WORKER_STAFF:
return STUDY_ROLE_CHOICES
elif worker_type == WORKER_HEALTH_PARTNER:
return HEALTH_PARTNER_ROLE_CHOICES
elif worker_type == WORKER_VOUCHER_PARTNER:
return VOUCHER_PARTNER_ROLE_CHOICES
else:
raise TypeError("{} Unknown worker type".format(worker_type))
Any suggestion? @piotr.gawron
Edited by Carlos Vega