delete states if it exists on run (#3901)

* delete states if it exists

* simplify ImmutableComputedVar.__get__ (#3902)

* simplify ImmutableComputedVar.__get__

* ruff it

---------

Co-authored-by: benedikt-bartscher <31854409+benedikt-bartscher@users.noreply.github.com>
This commit is contained in:
Khaleel Al-Adhami 2024-09-09 17:59:40 -07:00 committed by GitHub
parent 84ec08616b
commit fb721e1d12
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 0 deletions

View File

@ -16,6 +16,7 @@ from reflex_cli.utils import dependency
from reflex import constants from reflex import constants
from reflex.config import get_config from reflex.config import get_config
from reflex.custom_components.custom_components import custom_components_cli from reflex.custom_components.custom_components import custom_components_cli
from reflex.state import reset_disk_state_manager
from reflex.utils import console, redir, telemetry from reflex.utils import console, redir, telemetry
# Disable typer+rich integration for help panels # Disable typer+rich integration for help panels
@ -180,6 +181,9 @@ def _run(
if prerequisites.needs_reinit(frontend=frontend): if prerequisites.needs_reinit(frontend=frontend):
_init(name=config.app_name, loglevel=loglevel) _init(name=config.app_name, loglevel=loglevel)
# Delete the states folder if it exists.
reset_disk_state_manager()
# Find the next available open port if applicable. # Find the next available open port if applicable.
if frontend: if frontend:
frontend_port = processes.handle_port( frontend_port = processes.handle_port(

View File

@ -2499,6 +2499,14 @@ def state_to_schema(
) )
def reset_disk_state_manager():
"""Reset the disk state manager."""
states_directory = prerequisites.get_web_dir() / constants.Dirs.STATES
if states_directory.exists():
for path in states_directory.iterdir():
path.unlink()
class StateManagerDisk(StateManager): class StateManagerDisk(StateManager):
"""A state manager that stores states in memory.""" """A state manager that stores states in memory."""