{"record":{"id":"59ec8252e239d5f5","repo":"Lightning-AI/pytorch-lightning","slug":"self-log-on-step-false-on-epoch-false-is-not","errorCode":null,"errorMessage":"\"`self.log(on_step=False, on_epoch=False)` is not useful.\"","messagePattern":"\"`self\\.log\\(on_step=False, on_epoch=False\\)` is not useful\\.\"","errorType":"validation","errorClass":"MisconfigurationException","httpStatus":null,"severity":"error","filePath":"src/lightning/pytorch/trainer/connectors/logger_connector/result.py","lineNumber":123,"sourceCode":"@dataclass\nclass _Metadata:\n    fx: str\n    name: str\n    prog_bar: bool = False\n    logger: bool = True\n    on_step: bool = False\n    on_epoch: bool = True\n    # https://github.com/pytorch/pytorch/issues/96197\n    reduce_fx: Callable = torch.mean\n    enable_graph: bool = False\n    add_dataloader_idx: bool = True\n    dataloader_idx: Optional[int] = None\n    metric_attribute: Optional[str] = None\n    _sync: Optional[_Sync] = None\n\n    def __post_init__(self) -> None:\n        if not self.on_step and not self.on_epoch:\n            raise MisconfigurationException(\"`self.log(on_step=False, on_epoch=False)` is not useful.\")\n        self._parse_reduce_fx()\n\n    def _parse_reduce_fx(self) -> None:\n        error = (\n            \"Only `self.log(..., reduce_fx={min,max,mean,sum})` are supported.\"\n            \" If you need a custom reduction, please log a `torchmetrics.Metric` instance instead.\"\n            f\" Found: {self.reduce_fx}\"\n        )\n        if isinstance(self.reduce_fx, str):\n            reduce_fx = self.reduce_fx.lower()\n            if reduce_fx == \"avg\":\n                reduce_fx = \"mean\"\n            if reduce_fx not in (\"min\", \"max\", \"mean\", \"sum\"):\n                raise MisconfigurationException(error)\n            self.reduce_fx = getattr(torch, reduce_fx)\n        elif self.is_custom_reduction:\n            raise MisconfigurationException(error)\n","sourceCodeStart":105,"sourceCodeEnd":141,"githubUrl":"https://github.com/Lightning-AI/pytorch-lightning/blob/9fed5c27d2a62ff0efd6c3573599921d6ff67c14/src/lightning/pytorch/trainer/connectors/logger_connector/result.py#L105-L141","documentation":"A _Metadata result record created via self.log must be aggregated either per step or per epoch (or both). __post_init__ rejects on_step=False, on_epoch=False because the logged value would be computed and then never surfaced anywhere — it is a no-op that hides bugs.","triggerScenarios":"self.log('x', x, on_step=False, on_epoch=False) — both aggregation flags explicitly disabled; the same error is raised for any Result/Metric construction path that funnels into _Metadata.__post_init__.","commonSituations":"Disabling on_epoch for a training metric and on_step for cleanup, accidentally ending with both False; copying log calls between hooks and flipping flags to silence the on_step/on_epoch validators until both end up False; programmatic logging loops that set flags from config.","solutions":["Enable at least one flag: on_step=True or on_epoch=True depending on the hook's allowed set","If you only want the value on the progress bar, still keep an aggregation flag: self.log('x', x, prog_bar=True, on_step=True)","If you do not want the metric at all, remove the self.log call"],"exampleFix":"# before\nself.log('ratio', r, on_step=False, on_epoch=False)\n\n# after\nself.log('ratio', r, on_step=True, on_epoch=False)","handlingStrategy":"validation","validationCode":"assert on_step or on_epoch, \"self.log requires on_step=True or on_epoch=True\"","typeGuard":"def is_useful_log(on_step: bool, on_epoch: bool) -> bool:\n    return on_step or on_epoch","tryCatchPattern":null,"preventionTips":["Never set both flags False; delete the log call instead","Centralize flag choices in a helper that asserts at least one True","Code-review log calls that flip flags to silence validator errors"],"tags":["pytorch-lightning","logging","aggregation","misconfiguration"],"backgroundTag":"no-op-logging-call","analyzedSha":"9fed5c27d2a62ff0efd6c3573599921d6ff67c14","analyzedAt":"2026-08-28T11:52:41.083Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}