Raise ImportError in python_script (#134792)

This commit is contained in:
G Johansson 2025-01-06 14:52:40 +01:00 committed by Franck Nijhof
parent 09ffa38ddf
commit eda60073ee
No known key found for this signature in database
GPG Key ID: D62583BA8AB11CA3
2 changed files with 2 additions and 2 deletions

View File

@ -180,7 +180,7 @@ def guarded_import(
# Allow import of _strptime needed by datetime.datetime.strptime
if name == "_strptime":
return __import__(name, globals, locals, fromlist, level)
raise ScriptError(f"Not allowed to import {name}")
raise ImportError(f"Not allowed to import {name}")
def guarded_inplacevar(op: str, target: Any, operand: Any) -> Any:

View File

@ -711,4 +711,4 @@ async def test_no_other_imports_allowed(
source = "import sys"
hass.async_add_executor_job(execute, hass, "test.py", source, {})
await hass.async_block_till_done(wait_background_tasks=True)
assert "Error executing script: Not allowed to import sys" in caplog.text
assert "ImportError: Not allowed to import sys" in caplog.text