From 19634f2589155d5d949b43fdcd8fcf66635f71e4 Mon Sep 17 00:00:00 2001
From: Valentin Lorentz <vlorentz@softwareheritage.org>
Date: Mon, 19 Aug 2019 14:33:58 +0200
Subject: [PATCH] Allow -1 as Content length.

It denotes files whose length is unknown.
---
 swh/model/model.py | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/swh/model/model.py b/swh/model/model.py
index 776f729e..b741ae7c 100644
--- a/swh/model/model.py
+++ b/swh/model/model.py
@@ -341,8 +341,10 @@ class Content(BaseModel):
     @length.validator
     def check_length(self, attribute, value):
         """Checks the length is positive."""
-        if value < 0:
-            raise ValueError('Length must be positive.')
+        if self.status == 'absent' and value < -1:
+            raise ValueError('Length must be positive or -1.')
+        elif self.status != 'absent' and value < 0:
+            raise ValueError('Length must be positive, unless status=absent.')
 
     @reason.validator
     def check_reason(self, attribute, value):
-- 
GitLab