{"record":{"id":"cad04fee4a595d84","repo":"microsoft/qlib","slug":"please-implement-the-exists-method","errorCode":null,"errorMessage":"Please implement the `exists` method","messagePattern":"Please implement the `exists` method","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"qlib/utils/objm.py","lineNumber":66,"sourceCode":"            loaded object\n        \"\"\"\n        raise NotImplementedError(f\"Please implement the `load_obj` method\")\n\n    def exists(self, name: str) -> bool:\n        \"\"\"\n        if the object named `name` exists\n\n        Parameters\n        ----------\n        name : str\n            name of the objecT\n\n        Returns\n        -------\n        bool:\n            If the object exists\n        \"\"\"\n        raise NotImplementedError(f\"Please implement the `exists` method\")\n\n    def list(self) -> list:\n        \"\"\"\n        list the objects\n\n        Returns\n        -------\n        list:\n            the list of returned objects\n        \"\"\"\n        raise NotImplementedError(f\"Please implement the `list` method\")\n\n    def remove(self, fname=None):\n        \"\"\"remove.\n\n        Parameters\n        ----------\n        fname :","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/microsoft/qlib/blob/79633dd9506ea689e5400dea0197717b5b3d74b7/qlib/utils/objm.py#L48-L84","documentation":"exists(name) is the membership-check method of the abstract ObjManager interface (does an object with this name exist?). The base class deliberately raises NotImplementedError so every concrete backend defines its own existence semantics (file present, key present in DB, etc.).","triggerScenarios":"ObjManager().exists('name'), or a custom subclass missing an exists override while application code calls manager.exists(name) before load_obj to avoid load errors.","commonSituations":"Cache-invalidation logic (`if not mgr.exists(name): save(...)`) written against a custom manager; upgrading qlib versions where exists became expected on all managers; test doubles that skip rarely-used methods.","solutions":["Use FileManager, whose exists() checks the file in its managed directory.","Implement exists(self, name) -> bool in your subclass (e.g. return (self.path / name).exists() or a backend HEAD request).","If you cannot modify the class, replace the exists() call with a try/except around load_obj catching FileNotFoundError/KeyError."],"exampleFix":"// before\nif ObjManager().exists('model_v1'):  # NotImplementedError\n    obj = mgr.load_obj('model_v1')\n\n// after\nif FileManager(path='./objs').exists('model_v1'):\n    obj = mgr.load_obj('model_v1')","handlingStrategy":"try-catch","validationCode":"from qlib.utils.objm import ObjManager\nif type(mgr).exists is ObjManager.exists:\n    raise RuntimeError('manager does not implement exists(); fix subclass')","typeGuard":"def supports_exists(mgr) -> bool:\n    return type(mgr).exists is not ObjManager.exists","tryCatchPattern":"try:\n    present = mgr.exists(name)\nexcept NotImplementedError:\n    try:\n        mgr.load_obj(name)\n        present = True\n    except (FileNotFoundError, KeyError):\n        present = False","preventionTips":["Implement exists() as a cheap backend check in custom managers; never leave it abstract.","Cache name sets at save time if the backend cannot enumerate cheaply."],"tags":["qlib","objm","abstract-method","notimplementederror","existence-check"],"backgroundTag":null,"analyzedSha":"79633dd9506ea689e5400dea0197717b5b3d74b7","analyzedAt":"2026-08-15T07:01:27.511Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}