{"record":{"id":"eb016d31cf7a96a5","repo":"python-telegram-bot/python-telegram-bot","slug":"you-can-not-assign-a-new-value-to-disable-notifica","errorCode":null,"errorMessage":"You can not assign a new value to disable_notification after initialization.","messagePattern":"You can not assign a new value to disable_notification after initialization\\.","errorType":"validation","errorClass":"AttributeError","httpStatus":null,"severity":"error","filePath":"src/telegram/ext/_defaults.py","lineNumber":292,"sourceCode":"        \"\"\"\n        return self._parse_mode\n\n    @question_parse_mode.setter\n    def question_parse_mode(self, _: object) -> NoReturn:\n        raise AttributeError(\n            \"You can not assign a new value to question_parse_mode after initialization.\"\n        )\n\n    @property\n    def disable_notification(self) -> bool | None:\n        \"\"\":obj:`bool`: Optional. Sends the message silently. Users will\n        receive a notification with no sound.\n        \"\"\"\n        return self._disable_notification\n\n    @disable_notification.setter\n    def disable_notification(self, _: object) -> NoReturn:\n        raise AttributeError(\n            \"You can not assign a new value to disable_notification after initialization.\"\n        )\n\n    @property\n    def allow_sending_without_reply(self) -> bool | None:\n        \"\"\":obj:`bool`: Optional. Pass :obj:`True`, if the message\n        should be sent even if the specified replied-to message is not found.\n        \"\"\"\n        return self._allow_sending_without_reply\n\n    @allow_sending_without_reply.setter\n    def allow_sending_without_reply(self, _: object) -> NoReturn:\n        raise AttributeError(\n            \"You can not assign a new value to allow_sending_without_reply after initialization.\"\n        )\n\n    @property\n    def tzinfo(self) -> dtm.tzinfo:","sourceCodeStart":274,"sourceCodeEnd":310,"githubUrl":"https://github.com/python-telegram-bot/python-telegram-bot/blob/d3b69d2e9fb7af6c796f84516cfda751752c7cb7/src/telegram/ext/_defaults.py#L274-L310","documentation":"telegram.ext.Defaults disables assignment to its disable_notification property after construction by defining a setter that always raises AttributeError. Defaults objects are meant to be immutable once created; changing a default requires building a new Defaults instance and passing it to the Bot/Application. The library does this to guarantee that handlers and send methods observe consistent default settings.","triggerScenarios":"Assigning `bot.defaults.disable_notification = True` (or mutating any Defaults instance property) after Defaults(...) has been instantiated and handed to ext.Bot/ext.Application. Accessing the property itself is fine; only the setter raises.","commonSituations":"Developers trying to tweak notification behavior at runtime, porting code from older PTB versions where defaults were plain attributes, or writing config reload logic that mutates a Defaults object in place.","solutions":["Create a new Defaults instance with the desired value and pass it when constructing ext.Bot/ext.Application: Defaults(disable_notification=True).","Pass disable_notification explicitly per API call (e.g. bot.send_message(..., disable_notification=True)) instead of mutating defaults.","If you need mutable global defaults, keep your own config object and construct a fresh Defaults from it whenever you rebuild the bot."],"exampleFix":"// before\ndefaults = Defaults()\nbot = Bot(token=TOKEN, defaults=default)\ndefaults.disable_notification = True  # AttributeError\n\n// after\ndefaults = Defaults(disable_notification=True)\nbot = Bot(token=TOKEN, defaults=default)","handlingStrategy":"type-guard","validationCode":"from telegram.ext import Defaults\n\ndef can_set(d: Defaults) -> bool:\n    return False  # Defaults properties are always read-only after init","typeGuard":"from telegram.ext import Defaults\n\ndef is_defaults(obj: object) -> bool:\n    return isinstance(obj, Defaults)  # all its props are immutable; never setattr","tryCatchPattern":"try:\n    defaults.disable_notification = value\nexcept AttributeError:\n    defaults = Defaults(disable_notification=value)  # rebuild instead","preventionTips":["Treat Defaults as a value object: configure it entirely via constructor kwargs.","Store desired settings in your own dict and build Defaults from it on startup.","Lint for assignments to bot.defaults.* in code review."],"tags":["python-telegram-bot","immutable","attribute-error","defaults"],"backgroundTag":"immutable-object-assignment","analyzedSha":"d3b69d2e9fb7af6c796f84516cfda751752c7cb7","analyzedAt":"2026-08-28T16:18:54.805Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}