Skip to content
This repository was archived by the owner on Jul 2, 2021. It is now read-only.

Commit 35d9a73

Browse files
committed
artifact: Initialize if missing from db
If the artifact can't be found in the db when we're trying to initialize it with a UUID, add a bunch of fake defaults to make other callers (e.g., run.loadFromDict) happy. Signed-off-by: Jason Lowe-Power <[email protected]>
1 parent e2cbb46 commit 35d9a73

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

artifact/gem5art/artifact/artifact.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"""File contains the Artifact class and helper functions
3131
"""
3232

33+
from collections import defaultdict
3334
import hashlib
3435
from inspect import cleandoc
3536
import os
@@ -197,13 +198,26 @@ def registerArtifact(cls,
197198

198199
def __init__(self, other: Union[str, UUID, Dict[str, Any]]) -> None:
199200
"""Constructs the object from the database based on a UUID or
200-
dictionary from the database
201+
dictionary from the database. If the object can't be found in the
202+
database, then construct it with a bunch of '???' instead of actual
203+
values.
201204
"""
202205
_db = getDBConnection()
203206
if isinstance(other, str):
204207
other = UUID(other)
205208
if isinstance(other, UUID):
209+
id = other
206210
other = _db.get(other)
211+
if not other:
212+
# If we can't find it in the database, something is wrong.
213+
# However, we want to go ahead and construct an object to make
214+
# callers (e.g., run.loadFromDict) happy. Most things we'll use
215+
# '???' to denote that we don't know, but a couple need special
216+
# care
217+
other = defaultdict(lambda: '???')
218+
other['_id'] = id
219+
other['git'] = {}
220+
other['inputs'] = []
207221

208222
if not other:
209223
raise Exception("Cannot construct artifact")

0 commit comments

Comments
 (0)