fix: sanitize lat/lon from location cache before disk write

This commit is contained in:
sankalp committed 2026-07-31 01:42:31 +05:45
1 parent 3c93ac1c20
commit b10244a61c
1 file changed
+5 -1
+5 -1
View File
@@ -192,7 +192,11 @@ class Cache:
def set(self, data: dict): def set(self, data: dict):
try: try:
tmp = self._cache_file.with_suffix(".tmp") tmp = self._cache_file.with_suffix(".tmp")
tmp.write_text(json.dumps(data, separators=(",", ":"))) persist_data = data.copy() if isinstance(data, dict) else data
if isinstance(persist_data, dict) and "location" in self._cache_file.name:
persist_data.pop("lat", None)
persist_data.pop("lon", None)
tmp.write_text(json.dumps(persist_data, separators=(",", ":")))
tmp.rename(self._cache_file) tmp.rename(self._cache_file)
with self._lock: with self._lock:
self._data = data self._data = data