{"record":{"id":"2bafb790a3f07369","repo":"SeleniumHQ/selenium","slug":"cannot-set-readonly-attribute","errorCode":null,"errorMessage":"Cannot set readonly attribute","messagePattern":"Cannot set readonly attribute","errorType":"validation","errorClass":"AttributeError","httpStatus":null,"severity":"error","filePath":"py/selenium/webdriver/common/fedcm/account.py","lineNumber":34,"sourceCode":"# under the License.\n\nfrom enum import Enum\n\n\nclass LoginState(Enum):\n    SIGN_IN = \"SignIn\"\n    SIGN_UP = \"SignUp\"\n\n\nclass _AccountDescriptor:\n    def __init__(self, name):\n        self.name = name\n\n    def __get__(self, obj, cls) -> str | None:\n        return obj._account_data.get(self.name)\n\n    def __set__(self, obj, value) -> None:\n        raise AttributeError(\"Cannot set readonly attribute\")\n\n\nclass Account:\n    \"\"\"Represents an account displayed in a FedCM account list.\n\n    See: https://w3c-fedid.github.io/FedCM/#dictdef-identityprovideraccount\n         https://w3c-fedid.github.io/FedCM/#webdriver-accountlist\n    \"\"\"\n\n    account_id = _AccountDescriptor(\"accountId\")\n    email = _AccountDescriptor(\"email\")\n    name = _AccountDescriptor(\"name\")\n    given_name = _AccountDescriptor(\"givenName\")\n    picture_url = _AccountDescriptor(\"pictureUrl\")\n    idp_config_url = _AccountDescriptor(\"idpConfigUrl\")\n    terms_of_service_url = _AccountDescriptor(\"termsOfServiceUrl\")\n    privacy_policy_url = _AccountDescriptor(\"privacyPolicyUrl\")\n    login_state = _AccountDescriptor(\"loginState\")","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/py/selenium/webdriver/common/fedcm/account.py#L16-L52","documentation":"FedCM Account objects are read-only data containers backed by a descriptor that only implements __get__. Attempting to assign to any property (account_id, email, name, given_name, picture_url, idp_config_url, terms_of_service_url, privacy_policy_url, login_state) unconditionally raises AttributeError because __set__ always throws. The account data comes from the WebDriver's FedCM account-list response and is not meant to be mutated by the user.","triggerScenarios":"Calling `account.email = 'x@y.com'` or any assignment on an Account instance returned by driver.fedcm.account.list() / the FedCM dialog. Also triggers when code copies an Account and tries to overwrite a field, e.g. `acct.account_id = new_id`.","commonSituations":"Test code that retrieves the FedCM account list and then tries to mutate fields before clicking. Misunderstanding Account as a builder/config object rather than a server-returned snapshot. Generic helper code that round-trips and writes back attributes.","solutions":["Do not assign to Account properties; treat them as read-only views of the IdP response.","If you need modified data, construct a new plain dict from the account fields and mutate that dict instead.","Read values via the property (account.email) rather than trying to set them."],"exampleFix":"# before\nacct = driver.fedcm.dialog.account\nacct.email = 'override@example.com'  # raises AttributeError\n\n# after\nacct = driver.fedcm.dialog.account\nemail = acct.email  # read-only access\nmodified = {'email': 'override@example.com', 'name': acct.name}  # separate dict","handlingStrategy":"type-guard","validationCode":"from typing import getmemberdescriptors\n# Account fields are read-only by design; there is no valid assignment.\n# Validate intent before any setattr:\ndef is_writable_account_attr(name: str) -> bool:\n    return name not in {'account_id','email','name','given_name','picture_url','idp_config_url','terms_of_service_url','privacy_policy_url','login_state'}","typeGuard":"from selenium.webdriver.common.fedcm.account import Account\n# Read-only: guard against accidental assignment\nif isinstance(acct, Account):\n    email = acct.email  # only read","tryCatchPattern":"try:\n    account = driver.fedcm.dialog.account\n    email = account.email  # safe read\nexcept AttributeError:\n    # only if you mistakenly tried to set; reading never raises\n    pass","preventionTips":["Treat Account objects as immutable snapshots from the server.","Never use setattr() or direct assignment on Account instances.","Copy needed fields into a local dict if you must transform them."],"tags":["fedcm","readonly","attribute-error","descriptor"],"backgroundTag":null,"analyzedSha":"aa36b38e696a0909e973bdf5e2f9031ffe842c4b","analyzedAt":"2026-08-14T02:32:32.244Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}