Skip to content

Introduce a new Persistable mixin #266

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open

Introduce a new Persistable mixin #266

wants to merge 20 commits into from

Conversation

falkoschindler
Copy link
Contributor

@falkoschindler falkoschindler commented Mar 11, 2025

This PR implements a Persistable mixin as an alternative to the existing persistence mechanism. It works as a standalone module without the need for a globally managed registry. To avoid cyclic imports, it doesn't even use RoSys' on_repeat and on_shutdown hooks, but uses NiceGUI's app.timer and app.on_shutdown instead.

A new example demonstrates the intended use:

  • Classes can derive from Persistable if they want to support persistence. If so, they need to overwrite the abstract methods backup_to_dict() and restore_to_dict() to define the serialization and deserialization.
  • The user can call persistent() to make individual objects persistent (builder pattern). This opt-in approach gives full control to the user and allows more customization (key, path, intervals, ...) than before.

At the moment I see the following remaining tasks:

  • remove TODO markers in persistable.py (we keep the defaults)
  • validate key (only letters, digits, dash, underscore)
  • app.on_shutdown(self.sync_backup) --> or app.on_shutdown(self. _sync_backup_if_requested)
  • remove delete_persistence()
  • add pytests
  • add documentation (how?)
  • implement something like export_button and import_button for persistables?
  • use new Persistable for builtin RoSys modules
  • write migration guide: derive from Persistable, add .persistent() calls, rename backup and restore methods
  • remove old persistence registry and PersistentModule class

@falkoschindler falkoschindler added the enhancement New feature or request label Mar 11, 2025
@falkoschindler falkoschindler added this to the 0.23.0 milestone Mar 11, 2025
@falkoschindler falkoschindler modified the milestones: 0.23.0, 0.24.0 Mar 28, 2025
@falkoschindler falkoschindler self-assigned this Mar 28, 2025
@falkoschindler falkoschindler marked this pull request as ready for review April 25, 2025 15:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant