Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ accepts both, but the store flags the old spelling as deprecated

## Unreleased

### Fixes

- A failed on-demand request no longer comes back after a restart as the
session it ended. A failed request ends any running session, but the
saved copy of that session (`display_on_demand_config`) was left behind,
so the next restart of the display resumed it.

## 3.8.2

The display hands freed memory back to the OS (#774), and sports consolidation
Expand Down
10 changes: 7 additions & 3 deletions src/display_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,6 @@ def load_single_plugin(plugin_id):
except Exception: # pylint: disable=broad-except
cached_session = None
if self.on_demand_active or cached_session:
self.cache_manager.clear_cache('display_on_demand_config')
self._set_on_demand_error('restore-failed')
# Its state machine no longer describes what runs; let the last
# snapshot go stale (readers then say unknown) rather than keep
Expand Down Expand Up @@ -1817,8 +1816,14 @@ def _publish_on_demand_state(self) -> None:
logger.error("Failed to publish on-demand state: %s", err, exc_info=True)

def _set_on_demand_error(self, message: str) -> None:
"""Set on-demand state to error and publish."""
"""Set on-demand state to error and publish.

Ends any running session, so its saved copy goes too: a failed
request that replaced a session left display_on_demand_config
behind, and the next restart resumed the session that had ended.
"""
self._reset_on_demand_fields()
self.cache_manager.clear_cache('display_on_demand_config')
self.on_demand_status = 'error'
self.on_demand_last_error = message
self.on_demand_last_event = None
Expand Down Expand Up @@ -2756,7 +2761,6 @@ def _populate_on_demand_modes_from_plugin(self) -> None:
logger.error("On-demand session for plugin '%s' cannot resume after the "
"restart: the plugin has no loaded display modes (did it "
"fail to load?); ending it", plugin_id)
self.cache_manager.clear_cache('display_on_demand_config')
self._set_on_demand_error('restore-failed')
return

Expand Down
9 changes: 9 additions & 0 deletions test/test_on_demand_disabled_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,15 @@ def test_a_failed_request_that_ends_the_session_unloads_it(self, controller):
assert controller.current_display_mode == 'clock'
assert controller.force_change is True

def test_a_failed_request_that_ends_the_session_drops_its_saved_copy(self, controller):
"""Otherwise the next restart resumes the session that just ended."""
_start(controller, plugin_id='clock')
controller.cache_manager.clear_cache.reset_mock()

_start(controller, plugin_id='uninstalled')

controller.cache_manager.clear_cache.assert_called_once_with('display_on_demand_config')

def test_a_plugin_enabled_during_the_session_stays_loaded(self, controller):
_start(controller)
controller.test_config['preview-me'] = {'enabled': True}
Expand Down
Loading