Skip to content

fix(backup): report an unset completed_at as None - #2217

Open
RaphaelFakhri wants to merge 4 commits into
weaviate:mainfrom
RaphaelFakhri:fix/zero-completed-at
Open

RaphaelFakhri wants to merge 4 commits into
weaviate:mainfrom
RaphaelFakhri:fix/zero-completed-at

Conversation

@RaphaelFakhri

Copy link
Copy Markdown

What this changes

Weaviate serializes the completedAt timestamp of a backup or export that has not finished yet as Go's zero time, 0001-01-01T00:00:00.000Z. The client parsed that value as-is, so for a running backup or export:

  • client.backup.list_backups(...) returned completed_at=datetime(1, 1, 1, tzinfo=UTC).
  • client.export.get_status(...) returned completed_at=datetime(1, 1, 1, tzinfo=UTC).

Both fields are typed Optional[datetime] with a None default, so code that checks completed_at is None to detect an unfinished operation, or that computes a duration from it, gets a wrong answer.

This change adds a field validator to BackupListReturn.completed_at and ExportStatusReturn.completed_at that maps the zero time to None. Real timestamps pass through unchanged.

Fixes #2216

Reproduction

Against Weaviate 1.40.0 with backup-filesystem and EXPORT_ENABLED=true:

c.backup.create(backup_id="bk2", backend=BackupStorage.FILESYSTEM)
print(c.backup.list_backups(backend=BackupStorage.FILESYSTEM)[0].completed_at)
# before: 0001-01-01 00:00:00+00:00
# after:  None

The raw response from GET /v1/backups/filesystem while the backup runs:

[{"classes":["Article"],"completedAt":"0001-01-01T00:00:00.000Z","id":"bk1","startedAt":"2026-10-21T06:49:36.565Z","status":"STARTED"}]

Tests

  • test/test_backup.py: an unset completedAt maps to None; a set one is kept.
  • test/test_export.py (new): the same two cases for ExportStatusReturn.

pytest test/test_backup.py test/test_export.py: 2 of the new tests fail without the fix and all 7 pass with it. pytest test passes (546 passed, 1 skipped). ruff format, ruff check, and flake8 are clean on the changed files.

Weaviate serializes the completedAt of a backup or export that is still
running as Go's zero time, 0001-01-01T00:00:00.000Z. list_backups() and
export.get_status() returned it as datetime(1, 1, 1) instead of None.

@orca-security-eu orca-security-eu Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Orca Security Scan Summary

Status Check Issues by priority
Passed Passed Infrastructure as Code high 0   medium 0   low 0   info 0 View in Orca
Passed Passed SAST high 0   medium 0   low 0   info 0 View in Orca
Passed Passed Secrets high 0   medium 0   low 0   info 0 View in Orca
Passed Passed Vulnerabilities high 0   medium 0   low 0   info 0 View in Orca

@weaviate-git-bot

Copy link
Copy Markdown

To avoid any confusion in the future about your contribution to Weaviate, we work with a Contributor License Agreement. If you agree, you can simply add a comment to this PR that you agree with the CLA so that we can merge.

beep boop - the Weaviate bot 👋🤖

PS:
Are you already a member of the Weaviate Forum?

@RaphaelFakhri

Copy link
Copy Markdown
Author

I agree with the Weaviate Contributor License Agreement.

@dirkkul dirkkul left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

could you also add a few asserts to the existing integration tests, in addition to your unit tests? two of them can see an operation while it is still running:

  • test_list_backup in integration/test_backup_v4.py lists the backups right after create
  • test_create_export_without_waiting in integration/test_export.py polls get_status until it returns SUCCESS

in both, completed_at should be None while the backup or export is still running. it's fine if a run only sometimes catches the operation before it finishes, so the tests need no other changes.

possible asserts
# test_list_backup, after list_backups
backup = next(b for b in backups if b.backup_id.lower() == backup_id.lower())
if backup.status in (BackupStatus.STARTED, BackupStatus.TRANSFERRING):
    assert backup.completed_at is None

# test_create_export_without_waiting, in the polling loop
if status.status == ExportStatus.SUCCESS:
    assert status.completed_at is not None
    break
assert status.completed_at is None

reviewed with claude code, I went through every comment below myself

Comment thread weaviate/backup/backup.py Outdated
from weaviate.backup.backup_location import _BackupLocationConfig


def _zero_time_to_none(value: Optional[datetime]) -> Optional[datetime]:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

since #2244 was merged, main has a second zero-time check, for a user's created_at. _parse_optional_timestamp in weaviate/users/base.py compares against its own _GO_ZERO_TIME. could we move your _zero_time_to_none into weaviate/util.py and call it from _parse_optional_timestamp too? then the client has one zero-time check, and export.py imports it from util instead of a private helper from backup.py.

how I checked

I merged main into this branch locally and made the change, which touches 4 files at +12/-16. import weaviate still works, since util.py imports nothing from backup or users, and pytest test/ gives 574 passed, 1 skipped. The change leaves the timezone import in users/base.py unused, so that import goes too.

def _parse_optional_timestamp(value: Optional[str]) -> Optional[datetime]:
    if value is None:
        return None
    return _zero_time_to_none(datetime.fromisoformat(value.replace("Z", "+00:00")))

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done in d7e618d, after merging main. _zero_time_to_none is now in weaviate/util.py. backup.py, export.py and _parse_optional_timestamp in weaviate/users/base.py import it from there, and _GO_ZERO_TIME and the unused timezone import are gone. pytest test/ gives 576 passed, 1 skipped.

@RaphaelFakhri

RaphaelFakhri commented Nov 15, 2026 •

Copy link
Copy Markdown
Author

@dirkkul Added both asserts in d7e618d, as in your suggestion. I ran integration/test_backup_v4.py::test_list_backup and integration/test_export.py::test_create_export_without_waiting against Weaviate 1.40.2. Both pass on this branch in 7 runs. Without the validators, one of 3 runs of test_list_backup caught a STARTED backup and failed on completed_at == datetime(1, 1, 1, 0, 0, tzinfo=TzInfo(0)). Exports finish fast locally: polling 5 small exports caught one TRANSFERRING status, and its completed_at was None on this branch.

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.

Running backups and exports report completed_at as year 1 instead of None

3 participants