Skip to content

AttributeError when a WorkerVersion has a JSON configuration that is not an object

Sentry Issue: ARKINDEX-BACKEND-1SY

AttributeError: 'str' object has no attribute 'items'
(12 additional frame(s) were not displayed)
...
  File "rest_framework/serializers.py", line 246, in data
    self._data = self.to_representation(self.instance)
  File "rest_framework/serializers.py", line 663, in to_representation
    return [
  File "rest_framework/serializers.py", line 664, in <listcomp>
    self.child.to_representation(item) for item in iterable
  File "rest_framework/serializers.py", line 515, in to_representation
    ret[field.field_name] = field.to_representation(attribute)
  File "rest_framework/fields.py", line 1731, in to_representation
    for key, val in value.items()

There are three workers in preprod, one in demo and zero in prod where this occurs. An SQL query can find these:

SELECT * FROM process_worker
WHERE EXISTS (
    SELECT 1 FROM process_workerversion
    WHERE jsonb_typeof(configuration) <> 'object'
    AND worker_id = process_worker.id
);

This could be added as a database constraint, a CHECK (jsonb_typeof(configuration) = 'object'). We may need to do this on every JSONField we use, not just on WorkerVersion.configuration.

Edited by Erwan Rouchet