diff --git a/swh/model/model.py b/swh/model/model.py --- a/swh/model/model.py +++ b/swh/model/model.py @@ -624,6 +624,8 @@ content = super().to_dict() if content["data"] is None: del content["data"] + if content["ctime"] is None: + del content["ctime"] return content @classmethod diff --git a/swh/model/tests/test_hypothesis_strategies.py b/swh/model/tests/test_hypothesis_strategies.py --- a/swh/model/tests/test_hypothesis_strategies.py +++ b/swh/model/tests/test_hypothesis_strategies.py @@ -123,11 +123,17 @@ @given(objects()) def test_model_to_dicts(obj_type_and_obj): - (obj_type, object_) = obj_type_and_obj + _, object_ = obj_type_and_obj + object_type = object_.object_type obj_dict = object_.to_dict() assert_nested_dict(obj_dict) - if obj_type == "content": - COMMON_KEYS = set(DEFAULT_ALGORITHMS) | {"length", "status", "ctime"} + if object_type in ("content", "skipped_content"): + COMMON_KEYS = set(DEFAULT_ALGORITHMS) | {"length", "status"} + if ( + object_type == "content" and object_.ctime is not None + ) or object_type == "skipped_content": + COMMON_KEYS |= {"ctime"} + if obj_dict["status"] == "visible": assert set(obj_dict) == COMMON_KEYS | {"data"} elif obj_dict["status"] == "absent": @@ -136,9 +142,9 @@ assert set(obj_dict) == COMMON_KEYS | {"data"} else: assert False, obj_dict - elif obj_type == "release": + elif object_type == "release": assert obj_dict["target_type"] in target_types - elif obj_type == "snapshot": + elif object_type == "snapshot": for branch in obj_dict["branches"].values(): assert branch is None or branch["target_type"] in target_types