{"record":{"id":"b2e7cb0575bca496","repo":"Lightning-AI/pytorch-lightning","slug":"self-class-name-should-have-been-setu","errorCode":null,"errorMessage":"`{self.__class__.__name__}` should have been `setup` with a `CombinedLoader`.","messagePattern":"`(.+?)` should have been `setup` with a `CombinedLoader`\\.","errorType":"exception","errorClass":"MisconfigurationException","httpStatus":null,"severity":"error","filePath":"src/lightning/pytorch/loops/fetchers.py","lineNumber":42,"sourceCode":"\ndef _profile_nothing() -> None:\n    pass\n\n\nclass _DataFetcher(Iterator):\n    def __init__(self) -> None:\n        self._combined_loader: Optional[CombinedLoader] = None\n        self.iterator: Optional[Iterator] = None\n        self.fetched: int = 0\n        self.done: bool = False\n        self.length: Optional[int] = None\n        self._start_profiler = _profile_nothing\n        self._stop_profiler = _profile_nothing\n\n    @property\n    def combined_loader(self) -> CombinedLoader:\n        if self._combined_loader is None:\n            raise MisconfigurationException(\n                f\"`{self.__class__.__name__}` should have been `setup` with a `CombinedLoader`.\"\n            )\n        return self._combined_loader\n\n    def setup(self, combined_loader: CombinedLoader) -> None:\n        self._combined_loader = combined_loader\n\n    @override\n    def __iter__(self) -> \"_DataFetcher\":\n        self.iterator = iter(self.combined_loader)\n        self.reset()\n        return self\n\n    @override\n    def __next__(self) -> _ITERATOR_RETURN:\n        assert self.iterator is not None\n        self._start_profiler()\n        try:","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/Lightning-AI/pytorch-lightning/blob/9fed5c27d2a62ff0efd6c3573599921d6ff67c14/src/lightning/pytorch/loops/fetchers.py#L24-L60","documentation":"DataFetcher.combined_loader raises MisconfigurationException when its _combined_loader attribute is None, i.e. setup(combined_loader) was never called (or reset) before the property was accessed. The fetcher must be set up by the training/eval loop before iteration.","triggerScenarios":"Accessing fetcher.combined_loader on a freshly constructed _DataFetcher (or after resetting) without calling fetcher.setup(loader); typically from custom loop code that subclasses or drives the fetcher manually.","commonSituations":"Custom training loops or tests that instantiate a fetcher and skip the Trainer's setup sequence; also calling internal loop APIs outside a running fit/validate.","solutions":["Call fetcher.setup(CombinedLoader(dataloaders)) before accessing combined_loader","Let the Trainer own fetcher setup — don't access it before trainer.state is RUNNING","If writing a custom loop, mirror the setup order used in lightning's fit_loop"],"exampleFix":"# before\nfetcher = _DataFetcher()\ncl = fetcher.combined_loader  # raises\n# after\nfrom lightning.pytorch.loops.utilities import _DataFetcher\nfrom lightning.pytorch.overrides.distributed import CombinedLoader  # illustrative\nfetcher.setup(CombinedLoader(dataloader))\ncl = fetcher.combined_loader","handlingStrategy":"validation","validationCode":"if fetcher._combined_loader is None:\n    fetcher.setup(CombinedLoader(train_dataloader))","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Don't touch loop internals before trainer.fit/validate has started setup","In custom loops, always call setup() on fetchers before reading combined_loader"],"tags":["lightning","loops","fetchers","setup-order","internal-api"],"backgroundTag":"uninitialized-resource-access","analyzedSha":"9fed5c27d2a62ff0efd6c3573599921d6ff67c14","analyzedAt":"2026-08-28T11:52:41.083Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}