Page MenuHomeSoftware Heritage

Web app: issue when trying to list save code now requests
Closed, MigratedEdits Locked

Description

The request querying the list of submitted save code now requests now ends up with error 500 in production.

This is the associated stack trace:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/django/core/handlers/exception.py", line 42, in inner
    response = get_response(request)
  File "/usr/lib/python3/dist-packages/django/core/handlers/base.py", line 187, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/usr/lib/python3/dist-packages/django/core/handlers/base.py", line 185, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/usr/lib/python3/dist-packages/swh/web/browse/views/origin_save.py", line 74, in _browse_origin_save_requests_list
    save_requests = get_save_origin_requests_from_queryset(save_requests)
  File "/usr/lib/python3/dist-packages/swh/web/common/origin_save.py", line 325, in get_save_origin_requests_from_queryset
    tasks = scheduler.get_tasks([sor.loading_task_id])
  File "/usr/lib/python3/dist-packages/swh/scheduler/api/client.py", line 51, in get_tasks
    return self.post('get_tasks', {'task_ids': task_ids})
  File "/usr/lib/python3/dist-packages/swh/core/api.py", line 128, in post
    return self._decode_response(response)
  File "/usr/lib/python3/dist-packages/swh/core/api.py", line 165, in _decode_response
    return decode_response(response)
  File "/usr/lib/python3/dist-packages/swh/core/serializers.py", line 29, in decode_response
    r = msgpack_loads(response.content)
  File "/usr/lib/python3/dist-packages/swh/core/serializers.py", line 175, in msgpack_loads
    return msgpack.unpackb(data, encoding='utf-8', object_hook=decode_types)
  File "msgpack/_unpacker.pyx", line 139, in msgpack._unpacker.unpackb (msgpack/_unpacker.cpp:2068)
  File "/usr/lib/python3/dist-packages/swh/core/serializers.py", line 170, in decode_types
    return eval(obj[b's'])
TypeError: eval() arg 1 must be a string, bytes or code object

I can not reproduce the issue in my local environment. Any idea what's going on here ?

Event Timeline

anlambert created this task.
anlambert added a project: Web app.

I managed to reproduce the issue in my local environment.

This comes from the fact that swh-core has been upgraded to v0.0.44, changing the way datetime.timedelta is serialized/deserialized (commit 67dcf30ecbe1).

My guess is that the scheduler service on saatchi got restarted with that new code while the gunicorn workers on moma still use the old one.
So there is a mismatch between serialized data and the deserializing method. So redeploying the webapp should fix the issue.

However,

When using the last swh-core version locally with the data on the swh-web production db, I now got the following error:

Traceback (most recent call last):
  File "test_scheduler_get_tasks.py", line 7, in <module>
    print(scheduler.get_tasks([sys.argv[1]]))
  File "/home/antoine/swh/swh-environment/swh-scheduler/swh/scheduler/api/client.py", line 51, in get_tasks
    return self.post('get_tasks', {'task_ids': task_ids})
  File "/home/antoine/swh/swh-environment/swh-core/swh/core/api.py", line 128, in post
    return self._decode_response(response)
  File "/home/antoine/swh/swh-environment/swh-core/swh/core/api.py", line 165, in _decode_response
    return decode_response(response)
  File "/home/antoine/swh/swh-environment/swh-core/swh/core/serializers.py", line 29, in decode_response
    r = msgpack_loads(response.content)
  File "/home/antoine/swh/swh-environment/swh-core/swh/core/serializers.py", line 186, in msgpack_loads
    return msgpack.unpackb(data, encoding='utf-8', object_hook=decode_types)
  File "msgpack/_unpacker.pyx", line 139, in msgpack._unpacker.unpackb (msgpack/_unpacker.cpp:2068)
  File "/home/antoine/swh/swh-environment/swh-core/swh/core/serializers.py", line 181, in decode_types
    return datetime.timedelta(**obj[b's'])
TypeError: type object argument after ** must be a mapping, not str

As scheduler tasks parameter are stored in the softwareheritage-scheduler database, some datetime.timedelta values
are still serialized using the old method so the new one fails on such data. I think we should ensure backward compatibility
for deserializing such cases.

olasd claimed this task.
olasd added a subscriber: olasd.

This got fixed by deploying frontend and backend with the same version of swh-core, making the serialization format for the scheduler data compatible again.