@classmethod
def from_artifact(cls, artifact):
    'Upsert logic to generate an ArtifactReference object from an artifact'
    obj = cls.query.get(_id=artifact.index_id())
    if (obj is not None):
        return obj
    try:
        obj = cls(_id=artifact.index_id(), artifact_reference=dict(cls=bson.Binary(dumps(artifact.__class__, protocol=2)), project_id=artifact.app_config.project_id, app_config_id=artifact.app_config._id, artifact_id=artifact._id))
        session(obj).flush(obj)
        return obj
    except pymongo.errors.DuplicateKeyError:
        session(obj).expunge(obj)
        return cls.query.get(_id=artifact.index_id())
Upsert logic to generate an ArtifactReference object from an artifact
@classmethod
def from_artifact(cls, artifact):
    
    obj = cls.query.get(_id=artifact.index_id())
    if (obj is not None):
        return obj
    try:
        obj = cls(_id=artifact.index_id(), artifact_reference=dict(cls=bson.Binary(dumps(artifact.__class__, protocol=2)), project_id=artifact.app_config.project_id, app_config_id=artifact.app_config._id, artifact_id=artifact._id))
        session(obj).flush(obj)
        return obj
    except pymongo.errors.DuplicateKeyError:
        session(obj).expunge(obj)
        return cls.query.get(_id=artifact.index_id())