{"record":{"id":"e56f38b48e4f4921","repo":"SeleniumHQ/selenium","slug":"no-script-with-key-script-key-existed-in-self","errorCode":null,"errorMessage":"No script with key: {script_key} existed in {self.pinned_scripts}","messagePattern":"No script with key: (.+?) existed in (.+?)","errorType":"exception","errorClass":"KeyError","httpStatus":null,"severity":"warning","filePath":"py/selenium/webdriver/remote/webdriver.py","lineNumber":572,"sourceCode":"\n    def unpin(self, script_key: ScriptKey) -> None:\n        \"\"\"Remove a pinned script from storage.\n\n        .. deprecated::\n            Use ``driver.script.unpin()`` instead, which uses the WebDriver BiDi protocol.\n\n        Example:\n            `driver.unpin(script_key)`\n        \"\"\"\n        warnings.warn(\n            \"unpin is deprecated, use driver.script.unpin() instead\",\n            DeprecationWarning,\n            stacklevel=2,\n        )\n        try:\n            self.pinned_scripts.pop(script_key.id)\n        except KeyError:\n            raise KeyError(f\"No script with key: {script_key} existed in {self.pinned_scripts}\") from None\n\n    def get_pinned_scripts(self) -> list[str]:\n        \"\"\"Return a list of all pinned scripts.\n\n        .. deprecated::\n            Use ``driver.script.pin()`` to manage preload scripts via the WebDriver BiDi protocol.\n\n        Example:\n            `pinned_scripts = driver.get_pinned_scripts()`\n        \"\"\"\n        warnings.warn(\n            \"get_pinned_scripts is deprecated, use driver.script.pin() to manage preload scripts instead\",\n            DeprecationWarning,\n            stacklevel=2,\n        )\n        return list(self.pinned_scripts)\n\n    def execute_script(self, script: str, *args) -> Any:","sourceCodeStart":554,"sourceCodeEnd":590,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/py/selenium/webdriver/remote/webdriver.py#L554-L590","documentation":"Raised by the deprecated `unpin` method when `self.pinned_scripts.pop(script_key.id)` raises KeyError — i.e. the given ScriptKey.id is not in the pinned_scripts registry. The method then re-raises a KeyError with a descriptive message. Note `unpin` is deprecated in favor of `driver.script.unpin()`.","triggerScenarios":"Calling driver.unpin(script_key) with a ScriptKey that was never pinned, was already unpinned, or whose id doesn't match an entry in pinned_scripts.","commonSituations":"Unpinning a script twice; holding stale ScriptKey references across a session restart; mixed usage of the old unpin() and the new script API.","solutions":["Migrate to driver.script.unpin() (the non-deprecated BiDi-based API).","Only unpin keys returned by a successful pin(); track them in a set.","Guard with `if script_key.id in driver.pinned_scripts` before unpinning."],"exampleFix":"# before\ndriver.unpin(key)  # KeyError if key.id not pinned\n\n# after\nif key.id in driver.pinned_scripts:\n    driver.unpin(key)  # or driver.script.unpin(key)","handlingStrategy":"validation","validationCode":"if script_key.id not in driver.pinned_scripts:\n    raise KeyError(f'{script_key.id} is not pinned')\ndriver.unpin(script_key)","typeGuard":"def is_pinned(driver, script_key) -> bool:\n    return script_key.id in driver.pinned_scripts","tryCatchPattern":"try:\n    driver.unpin(key)\nexcept KeyError:\n    # already unpinned or never pinned; nothing to do","preventionTips":["Track pinned ScriptKeys in a container and unpin each once.","Move to driver.script.pin/unpin; the legacy API is deprecated."],"tags":["scripts","deprecation","validation","webdriver"],"backgroundTag":null,"analyzedSha":"aa36b38e696a0909e973bdf5e2f9031ffe842c4b","analyzedAt":"2026-08-14T02:32:32.244Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}