{"record":{"id":"73cbd4114851efcf","repo":"pallets/flask","slug":"view-func-name-may-not-contain-a-dot-charact","errorCode":null,"errorMessage":"'view_func' name may not contain a dot '.' character.","messagePattern":"'view_func' name may not contain a dot '\\.' character\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/flask/sansio/blueprints.py","lineNumber":431,"sourceCode":"    def add_url_rule(\n        self,\n        rule: str,\n        endpoint: str | None = None,\n        view_func: ft.RouteCallable | None = None,\n        provide_automatic_options: bool | None = None,\n        **options: t.Any,\n    ) -> None:\n        \"\"\"Register a URL rule with the blueprint. See :meth:`.Flask.add_url_rule` for\n        full documentation.\n\n        The URL rule is prefixed with the blueprint's URL prefix. The endpoint name,\n        used with :func:`url_for`, is prefixed with the blueprint's name.\n        \"\"\"\n        if endpoint and \".\" in endpoint:\n            raise ValueError(\"'endpoint' may not contain a dot '.' character.\")\n\n        if view_func and hasattr(view_func, \"__name__\") and \".\" in view_func.__name__:\n            raise ValueError(\"'view_func' name may not contain a dot '.' character.\")\n\n        self.record(\n            lambda s: s.add_url_rule(\n                rule,\n                endpoint,\n                view_func,\n                provide_automatic_options=provide_automatic_options,\n                **options,\n            )\n        )\n\n    @t.overload\n    def app_template_filter(self, name: T_template_filter) -> T_template_filter: ...\n    @t.overload\n    def app_template_filter(\n        self, name: str | None = None\n    ) -> t.Callable[[T_template_filter], T_template_filter]: ...\n    @setupmethod","sourceCodeStart":413,"sourceCodeEnd":449,"githubUrl":"https://github.com/pallets/flask/blob/3596b1ab61cea85edb8970e83ff61daa073facf8/src/flask/sansio/blueprints.py#L413-L449","documentation":"Blueprint.add_url_rule also checks the view function's __name__ for a dot (when endpoint is not explicitly given, Flask would derive the endpoint from __name__, so a dotted __name__ causes the same collision). If view_func has __name__ containing '.', it raises ValueError. This commonly happens with functools.partial or nested functions.","triggerScenarios":"Passing a functools.partial as the view (its __name__ is absent/odd); a lambda or nested function whose __name__ contains a dot; a callable class instance or wrapped function whose __name__ includes a module path; view decorated in a way that sets a dotted __name__.","commonSituations":"Using @functools.wraps incorrectly leaving a dotted name; passing methods of a class (someclass.handler) as views; decorated views whose wrapper preserved a fully-qualified name.","solutions":["Pass an explicit undotted endpoint= so Flask does not derive one from __name__.","Rename the function so __name__ has no dot, or set view_func.__name__ to a clean identifier before registering.","For partials/wrappers, wrap with functools.wraps to a function whose __name__ is a plain identifier."],"exampleFix":"// before\nbp.add_url_rule('/run', view_func=functools.partial(handler, x=1))\n\n// after\nbp.add_url_rule('/run', endpoint='run', view_func=functools.partial(handler, x=1))","handlingStrategy":"type-guard","validationCode":"def safe_bp_add_url_rule(bp, rule, view_func=None, endpoint=None, **opts):\n    if view_func is not None and hasattr(view_func, '__name__') and '.' in view_func.__name__:\n        endpoint = endpoint or view_func.__name__.split('.')[-1]\n    bp.add_url_rule(rule, endpoint=endpoint, view_func=view_func, **opts)\n","typeGuard":"def view_name_is_dot_free(view_func) -> bool:\n    name = getattr(view_func, '__name__', None)\n    return name is None or '.' not in name\n","tryCatchPattern":null,"preventionTips":["Pass an explicit endpoint= when registering partials/wrappers as blueprint views.","Use functools.wraps to give wrappers a clean __name__.","Avoid passing methods of dotted class objects directly as views."],"tags":["flask","blueprint","endpoint","view-func","validation"],"backgroundTag":null,"analyzedSha":"3596b1ab61cea85edb8970e83ff61daa073facf8","analyzedAt":"2026-08-11T20:11:52.622Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}