From e77c94d52bfaa1e510ea2f31877ac56f6b448460 Mon Sep 17 00:00:00 2001
From: Valentin Lorentz <vlorentz@softwareheritage.org>
Date: Wed, 4 Sep 2019 14:36:01 +0200
Subject: [PATCH] Fix Revision.from_dict to allow optional fields.

---
 swh/model/model.py | 19 ++++++++-----------
 1 file changed, 8 insertions(+), 11 deletions(-)

diff --git a/swh/model/model.py b/swh/model/model.py
index 21bd45e2..badac8c6 100644
--- a/swh/model/model.py
+++ b/swh/model/model.py
@@ -283,19 +283,16 @@ class Revision(BaseModel):
 
     @classmethod
     def from_dict(cls, d):
+        d = d.copy()
         return cls(
-            id=d['id'],
-            message=d['message'],
-            author=Person.from_dict(d['author']),
-            committer=Person.from_dict(d['committer']),
-            date=TimestampWithTimezone.from_dict(d['date']),
+            id=d.pop('id'),
+            author=Person.from_dict(d.pop('author')),
+            committer=Person.from_dict(d.pop('committer')),
+            date=TimestampWithTimezone.from_dict(d.pop('date')),
             committer_date=TimestampWithTimezone.from_dict(
-                d['committer_date']),
-            type=RevisionType(d['type']),
-            directory=d['directory'],
-            synthetic=d['synthetic'],
-            metadata=d['metadata'],
-            parents=d['parents'])
+                d.pop('committer_date')),
+            type=RevisionType(d.pop('type')),
+            **d)
 
 
 @attr.s
-- 
GitLab