@@ -524,3 +524,43 @@ def test_csrf_config_read_only():
524524 app .config .csrf_token_name = "something_else"
525525 with pytest .raises (AttributeError ):
526526 app .config .csrf_header_name = "something_else"
527+
528+
529+ def test_init_app_with_flask_run_pattern ():
530+ """Test that init_app works correctly with the flask run pattern.
531+
532+ This tests the fix for https://github.com/plotly/dash/issues/3787
533+ where using flask run would cause a ValueError about duplicate blueprint
534+ registration because init_app was called twice (once automatically in
535+ __init__ with server=True, and once by the user in their create_app factory).
536+ """
537+ # Simulate the flask run pattern where:
538+ # 1. Dash app is created with server=True (default)
539+ # 2. User's create_app factory calls init_app with their Flask server
540+ external_server = Flask ("external_test" )
541+ app = Dash (__name__ )
542+
543+ # This should NOT raise "ValueError: The name '_dash_assets' is already registered"
544+ app .init_app (external_server )
545+
546+ # Verify the backend now uses the external server
547+ assert app .server is external_server
548+ assert app .backend .server is external_server
549+
550+
551+ def test_init_app_server_false_pattern ():
552+ """Test that init_app works correctly when server=False is used.
553+
554+ This tests the fix for https://github.com/plotly/dash/issues/3787
555+ where using server=False and then calling init_app would result in
556+ 404 errors because the backend's server reference was not updated.
557+ """
558+ external_server = Flask ("external_test_false" )
559+ app = Dash (__name__ , server = False )
560+
561+ # Call init_app with the external server
562+ app .init_app (external_server )
563+
564+ # Verify both the app and backend use the external server
565+ assert app .server is external_server
566+ assert app .backend .server is external_server
0 commit comments