diff --git a/supervisor/ingress.py b/supervisor/ingress.py index f53a3e2a3e5..e61ef3377c4 100644 --- a/supervisor/ingress.py +++ b/supervisor/ingress.py @@ -88,7 +88,7 @@ def _cleanup_sessions(self) -> None: now = utcnow() sessions = {} - sessions_data: dict[str, IngressSessionData] = {} + sessions_data: dict[str, dict[str, str | None]] = {} for session, valid in self.sessions.items(): # check if timestamp valid, to avoid crash on malformed timestamp try: @@ -102,7 +102,8 @@ def _cleanup_sessions(self) -> None: # Is valid sessions[session] = valid - sessions_data[session] = self.sessions_data.get(session) + if session_data := self.sessions_data.get(session): + sessions_data[session] = session_data # Write back self.sessions.clear() diff --git a/tests/test_ingress.py b/tests/test_ingress.py index 69b43991ebe..e7f9777b471 100644 --- a/tests/test_ingress.py +++ b/tests/test_ingress.py @@ -88,3 +88,14 @@ async def test_ingress_save_data(coresys: CoreSys, tmp_supervisor_data: Path): }, "ports": {}, } + + +async def test_ingress_reload_ignore_none_data(coresys: CoreSys): + """Test reloading ingress does not add None for session data and create errors.""" + session = coresys.ingress.create_session() + assert session in coresys.ingress.sessions + assert session not in coresys.ingress.sessions_data + + await coresys.ingress.reload() + assert session in coresys.ingress.sessions + assert session not in coresys.ingress.sessions_data