Skip to content

Only remove expired results in the ArangoDB backend's cleanup() - #11125

Open
MehrazRumman wants to merge 7 commits into
celery:mainfrom
MehrazRumman:fix/arangodb-cleanup-date-done
Open

MehrazRumman wants to merge 7 commits into
celery:mainfrom
MehrazRumman:fix/arangodb-cleanup-date-done

Conversation

@MehrazRumman

Copy link
Copy Markdown
Contributor

Note: Before submitting this pull request, please review our contributing
guidelines
& [Anti AI spamming Guidelines] (#10932). Before opening an AI based PR make sure you asked
in the discussion forum or in the related open issues first.

Description

Fixes #11122

The ArangoDB backend stores each result as the encoded meta, a JSON string, in the document's task field. cleanup() filtered on record.task.date_done < @checkpoint. On a string .date_done is null, which AQL sorts before any string, so every document was removed, including results stored a moment before and tasks still running. celery.backend_cleanup runs this daily under beat.

The query now parses task with JSON_PARSE() (or uses it as is if it's already an object), skips documents without a date_done, and compares DATE_TIMESTAMP(meta.date_done) with the cutoff in milliseconds, rather than comparing ISO strings, which can carry different UTC offsets.

Only celery/backends/arangodb.py changes. Documents without a date_done are kept now, where main removed them. That includes group results saved with GroupResult.save(), which only store result, so cleanup() no longer removes them at all.

Tests

Against ArangoDB 3.12.13 in Docker with pyArango 2.1.1, result_expires=86400. One result was stored now, one with its date_done set two days back, and one task was left STARTED, then cleanup() ran:

timezone main this PR
UTC all three removed only the 2-day-old result removed
Asia/Tokyo all three removed only the 2-day-old result removed

I also checked in AQL that DATE_TIMESTAMP() reads Python's isoformat() with microseconds and offsets: "2026-11-17T09:00:00.123456+09:00" and "2026-11-17T00:00:00.123456+00:00" give the same value. DATE_TIMESTAMP(null) is null, hence the explicit done != null.

test_backend_cleanup in t/unit/backends/test_arangodb.py asserted the old query text. It now checks that the query parses task, filters out null, and gets the cutoff as a millisecond timestamp. It fails on main and passes here. pytest t/unit/backends/test_arangodb.py: 14 passed. pre-commit passes on both files.

Not run: the integration and smoke suites. CI has no ArangoDB.

The backend stores each result as the encoded meta, a JSON string, in
the document's task field. cleanup() filtered on record.task.date_done,
which is null on a string, and AQL sorts null before any value, so
every result was removed, including ones stored a moment ago and tasks
still running. celery.backend_cleanup runs this daily under beat.

Parse the JSON to read date_done, skip results without one, and compare
instants with DATE_TIMESTAMP() instead of ISO strings, which can carry
different UTC offsets.
@codecov

codecov Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.35%. Comparing base (fddb3f8) to head (352b231).

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #11125   +/-   ##
=======================================
  Coverage   91.35%   91.35%           
=======================================
  Files         153      153           
  Lines       21889    21889           
  Branches     2721     2721           
=======================================
  Hits        19997    19997           
  Misses       1590     1590           
  Partials      302      302           
Flag Coverage Δ
unittests 91.33% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@auvipy auvipy added this to the 5.7.x milestone Nov 19, 2026
@auvipy
auvipy self-requested a review November 19, 2026 09:29
def cleanup(self):
if not self.expires:
return
checkpoint = (self.app.now() - self.expires_delta).isoformat()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is removing the isoformat fixing this bug?

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ArangoDB backend: cleanup() deletes every result, including ones just stored

2 participants