Skip to content

Stamps not supported in database backend #480

Open
@freddyheppell

Description

@freddyheppell

I've been trying to add stamps to a complex task canvas, but I've found that they don't get stored in the results table with result_extended enabled. I've attempted to trace why this isn't working and it seems that django-celery-results just doesn't retrieve stamp data.

In celery.backends.base.Base, there is a _get_result_meta() method, which builds extended metadata if extended results are enabled. Among other things on L494 this retrieves stamps and assigns them to the meta object.

In django-celery-results, collecting extended result data is instead performed in the django_celery_results.backends.database.DatabaseBackend by the _get_extended_properties() method, which doesn't do anything to stamps. The _get_meta_from_request() method retrieves metadata from the request, but there's nothing to actually put stamps into the metadata.

I've been able to fix this in my project by subclassing DatabaseBackend and overriding _get_meta_from_request():

from celery.backends.base import get_current_task
from django_celery_results.backends.database import DatabaseBackend as _DatabaseBackend

class DatabaseBackend(_DatabaseBackend):
    def _get_meta_from_request(self, request=None):
        meta = super()._get_meta_from_request(request)
        request = request or getattr(get_current_task(), "request", None)

        if getattr(request, 'stamps', None):
            meta["stamped_headers"] = request.stamped_headers
            meta.update(request.stamps)

        return meta

It seems the cache backend does support stamps as it doesn't override the _store_result() method of BaseKeyValueAttributeStore

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions