Skip to content

Commit

Permalink
Fix has_served_traffic safety check so it doesn't break notebook deve…
Browse files Browse the repository at this point in the history
…lopment (#694)
  • Loading branch information
wwwillchen authored Jul 30, 2024
1 parent 289acbc commit c0d2c4d
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion mesop/colab/colab_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

from absl import flags

from mesop.colab import colab_utils
from mesop.runtime import enable_debug_mode
from mesop.server.constants import EDITOR_PACKAGE_PATH, PROD_PACKAGE_PATH
from mesop.server.logging import log_startup
from mesop.server.server import configure_flask_app
from mesop.server.static_file_serving import configure_static_file_serving
from mesop.utils import colab_utils
from mesop.utils.host_util import get_default_host


Expand Down
2 changes: 1 addition & 1 deletion mesop/colab/colab_run_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

import pytest

from mesop.colab import colab_utils
from mesop.colab.colab_run import colab_run
from mesop.runtime import runtime
from mesop.utils import colab_utils


class FakeThread:
Expand Down
2 changes: 1 addition & 1 deletion mesop/colab/colab_show.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from mesop.colab import colab_utils
from mesop.utils import colab_utils


def colab_show(
Expand Down
1 change: 1 addition & 0 deletions mesop/runtime/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ py_library(
"//mesop/exceptions",
"//mesop/protos:ui_py_pb2",
"//mesop/security",
"//mesop/utils",
] + THIRD_PARTY_PY_FLASK,
)
11 changes: 10 additions & 1 deletion mesop/runtime/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from mesop.exceptions import MesopDeveloperException, MesopUserException
from mesop.key import Key
from mesop.security.security_policy import SecurityPolicy
from mesop.utils import colab_utils
from mesop.utils.backoff import exponential_backoff

from .context import Context
Expand Down Expand Up @@ -61,7 +62,15 @@ def context(self) -> Context:
return g._mesop_context

def create_context(self) -> Context:
self._has_served_traffic = True
# If running in prod mode, *always* enable the has served traffic safety check.
# If running in debug mode, only enable the has served traffic safety check if
# app is not running in IPython / notebook environments.
#
# We don't want to break iterative development where notebook app developers
# will want to register pages after traffic has been served.
# Unlike CLI (w/ hot reload), in notebook envs, runtime is *not* reset.
if not self.debug_mode or not colab_utils.is_running_ipython():
self._has_served_traffic = True
if len(self._state_classes) == 0:
states = {EmptyState: EmptyState()}
else:
Expand Down
File renamed without changes.

0 comments on commit c0d2c4d

Please sign in to comment.