From 05b89f26b67278bf97b30b02a327beadccc05624 Mon Sep 17 00:00:00 2001 From: Valentin Lorentz <vlorentz@softwareheritage.org> Date: Fri, 7 Feb 2020 16:02:04 +0100 Subject: [PATCH] Make content length mandatory. The current postgresql model refuses NULL values. --- swh/model/hypothesis_strategies.py | 2 +- swh/model/model.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/swh/model/hypothesis_strategies.py b/swh/model/hypothesis_strategies.py index 5433b2a7..8d3923c7 100644 --- a/swh/model/hypothesis_strategies.py +++ b/swh/model/hypothesis_strategies.py @@ -153,7 +153,7 @@ def skipped_contents(draw): return draw(builds( SkippedContent, - length=optional(integers(min_value=0, max_value=2**63-1)), + length=integers(min_value=-1, max_value=2**63-1), sha1=optional(sha1()), sha1_git=optional(sha1_git()), sha256=optional(binary(min_size=32, max_size=32)), diff --git a/swh/model/model.py b/swh/model/model.py index 8a60f181..215afdb2 100644 --- a/swh/model/model.py +++ b/swh/model/model.py @@ -406,7 +406,7 @@ class Content(BaseContent): @length.validator def check_length(self, attribute, value): """Checks the length is positive.""" - if self.status != 'absent' and value < 0: + if value < 0: raise ValueError('Length must be positive.') def to_dict(self): @@ -427,7 +427,7 @@ class SkippedContent(BaseContent): sha256 = attr.ib(type=Optional[bytes]) blake2s256 = attr.ib(type=Optional[bytes]) - length = attr.ib(type=Optional[int]) + length = attr.ib(type=int) status = attr.ib( type=str, @@ -451,7 +451,7 @@ class SkippedContent(BaseContent): @length.validator def check_length(self, attribute, value): """Checks the length is positive or -1.""" - if value is not None and value < -1: + if value < -1: raise ValueError('Length must be positive or -1.') def to_dict(self): -- GitLab