def from_dict(cls, d): """ Special from_dict to autoload the pydantic model from the location string """ model = d.get("model") if isinstance(model, str): model = dynamic_import(model) assert issubclass( model, BaseModel), "The resource model has to be a PyDantic Model" d["model"] = model return cls(**d)
def from_dict(cls, d): if isinstance(d["model"], str): d["model"] = dynamic_import(d["model"]) decoder = MontyDecoder() return cls(**{k: decoder.process_decoded(v) for k, v in d.items()})
def test_dynamic_import(): assert dynamic_import("maggma.stores", "MongoStore").__name__ == "MongoStore"
def from_dict(cls, d: Dict): if isinstance(d["model"], str): d["model"] = dynamic_import(d["model"]) d = {k: MontyDecoder().process_decoded(v) for k, v in d.items()} return cls(**d)