diff --git a/swh/model/hypothesis_strategies.py b/swh/model/hypothesis_strategies.py --- a/swh/model/hypothesis_strategies.py +++ b/swh/model/hypothesis_strategies.py @@ -180,7 +180,10 @@ def snapshots(draw, *, min_size=0, max_size=100, only_objects=False): branches = draw(dictionaries( keys=branch_names(), - values=branch_targets(only_objects=only_objects), + values=one_of( + none(), + branch_targets(only_objects=only_objects) + ), min_size=min_size, max_size=max_size, )) @@ -202,7 +205,7 @@ try: id_ = snapshot_identifier({ 'branches': { - name: branch.to_dict() + name: branch.to_dict() if branch else None for (name, branch) in branches.items()}}) except ValueError as e: for (source, target) in e.args[1]: diff --git a/swh/model/model.py b/swh/model/model.py --- a/swh/model/model.py +++ b/swh/model/model.py @@ -194,7 +194,7 @@ return { 'id': self.id, 'branches': { - name: branch.to_dict() + name: branch.to_dict() if branch else None for (name, branch) in self.branches.items() } } @@ -204,7 +204,7 @@ return cls( id=d['id'], branches={ - name: SnapshotBranch.from_dict(branch) + name: SnapshotBranch.from_dict(branch) if branch else None for (name, branch) in d['branches'].items() }) 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 @@ -59,4 +59,4 @@ assert object_['target_type'] in target_types elif obj_type == 'snapshot': for branch in object_['branches'].values(): - assert branch['target_type'] in target_types + assert branch is None or branch['target_type'] in target_types