Store: copy pending data (#59934)

This commit is contained in:
Paulus Schoutsen 2021-11-18 15:56:22 -08:00 committed by GitHub
parent 0fb21af07f
commit 442597928e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 42 additions and 11 deletions

View file

@ -4,6 +4,7 @@ from __future__ import annotations
import asyncio
from collections.abc import Callable
from contextlib import suppress
from copy import deepcopy
import inspect
from json import JSONEncoder
import logging
@ -133,6 +134,10 @@ class Store:
# If we didn't generate data yet, do it now.
if "data_func" in data:
data["data"] = data.pop("data_func")()
# We make a copy because code might assume it's safe to mutate loaded data
# and we don't want that to mess with what we're trying to store.
data = deepcopy(data)
else:
data = await self.hass.async_add_executor_job(
json_util.load_json, self.path