@classmethod
    def create(cls, data):
        foreign_id = data.get('foreign_id')
        src = Source.by_foreign_id(foreign_id)
        if src is None:
            src = cls()
            src.foreign_id = foreign_id or make_token()
        src.update(data)
        db.session.flush()
        return src
dataset/ETHPy150Open pudo/aleph/aleph/model/source.py/Source.create/original