diff --git a/swh/storage/cassandra/storage.py b/swh/storage/cassandra/storage.py --- a/swh/storage/cassandra/storage.py +++ b/swh/storage/cassandra/storage.py @@ -105,7 +105,9 @@ return summary def content_add(self, content: Iterable[Content]) -> Dict: - return self._content_add(list(content), with_data=True) + now = datetime.datetime.now(tz=datetime.timezone.utc) + contents = [attr.evolve(c, ctime=now) for c in content] + return self._content_add(list(contents), with_data=True) def content_update(self, content, keys=[]): raise NotImplementedError( @@ -253,7 +255,9 @@ } def skipped_content_add(self, content: Iterable[SkippedContent]) -> Dict: - return self._skipped_content_add(content) + now = datetime.datetime.now(tz=datetime.timezone.utc) + contents = [attr.evolve(c, ctime=now) for c in content] + return self._skipped_content_add(contents) def skipped_content_missing(self, contents): for content in contents: diff --git a/swh/storage/validate.py b/swh/storage/validate.py --- a/swh/storage/validate.py +++ b/swh/storage/validate.py @@ -4,7 +4,6 @@ # See top-level LICENSE file for more information import contextlib -import datetime from typing import Dict, Iterable, List, Union from swh.model.model import ( @@ -33,10 +32,6 @@ raise StorageArgumentException(*e.args) -def now(): - return datetime.datetime.now(tz=datetime.timezone.utc) - - class ValidatingProxyStorage: """Storage implementation converts dictionaries to swh-model objects before calling its backend, and back to dicts before returning results @@ -52,8 +47,7 @@ def content_add(self, content: Iterable[Dict]) -> Dict: with convert_validation_exceptions(): - contents = [Content.from_dict({**c, 'ctime': now()}) - for c in content] + contents = [Content.from_dict(c) for c in content] return self.storage.content_add(contents) def content_add_metadata(self, content: Iterable[Dict]) -> Dict: @@ -64,8 +58,7 @@ def skipped_content_add(self, content: Iterable[Dict]) -> Dict: with convert_validation_exceptions(): - contents = [SkippedContent.from_dict({**c, 'ctime': now()}) - for c in content] + contents = [SkippedContent.from_dict(c) for c in content] return self.storage.skipped_content_add(contents) def directory_add(self, directories: Iterable[Dict]) -> Dict: