Repository: litestar-org/litestar

Issue:
StaticFilesConfig and virtual directories
I'm trying to write a ``FileSystemProtocol`` to load files from the package data using [importlib_resources](https://importlib-resources.readthedocs.io/en/latest/using.html#). But because ``directories`` is defined as ``DirectoryPath``, pydantic checks if the given directories exist in the local filesystem. 

This is not generally true, especially in any kind of virtual filesystem (e.g. a zipped package). I think this condition should be relaxed to support virtual filesystems.

https://github.com/starlite-api/starlite/blob/9bb6dcd57c10a591377cf8e3a537e9292566d5b9/starlite/config/static_files.py#L32


Discussion:
I agree. Do you want to submit a PR?

Resolving patch:
diff --git a/starlite/plugins/sql_alchemy/plugin.py b/starlite/plugins/sql_alchemy/plugin.py
--- a/starlite/plugins/sql_alchemy/plugin.py
+++ b/starlite/plugins/sql_alchemy/plugin.py
@@ -77,9 +77,9 @@ def on_app_init(self, app: "Starlite") -> None:
         if self._config is not None:
             app.dependencies[self._config.dependency_key] = Provide(self._config.create_db_session_dependency)
             app.before_send.append(self._config.before_send_handler)  # type: ignore[arg-type]
+            app.on_startup.append(self._config.update_app_state)
             app.on_shutdown.append(self._config.on_shutdown)
             self._config.config_sql_alchemy_logging(app.logging_config)
-            self._config.update_app_state(state=app.state)
 
     @staticmethod
     def is_plugin_supported_type(value: Any) -> "TypeGuard[DeclarativeMeta]":


Test patch:
diff --git a/tests/plugins/sql_alchemy_plugin/test_sql_alchemy_config.py b/tests/plugins/sql_alchemy_plugin/test_sql_alchemy_config.py
--- a/tests/plugins/sql_alchemy_plugin/test_sql_alchemy_config.py
+++ b/tests/plugins/sql_alchemy_plugin/test_sql_alchemy_config.py
@@ -23,17 +23,17 @@
 @pytest.mark.parametrize("connection_string", ["sqlite+aiosqlite://", "sqlite://"])
 def test_sets_engine_and_session_maker(connection_string: str) -> None:
     config = SQLAlchemyConfig(connection_string=connection_string, use_async_engine="+aiosqlite" in connection_string)
-    app = Starlite(route_handlers=[], plugins=[SQLAlchemyPlugin(config=config)])
-    assert app.state.get(config.engine_app_state_key)
-    assert app.state.get(config.session_maker_app_state_key)
+    with create_test_client([], plugins=[SQLAlchemyPlugin(config=config)]) as client:
+        assert client.app.state.get(config.engine_app_state_key)
+        assert client.app.state.get(config.session_maker_app_state_key)
 
 
 @pytest.mark.parametrize("connection_string", ["sqlite+aiosqlite://", "sqlite://"])
 def test_dependency_creates_session(connection_string: str) -> None:
     config = SQLAlchemyConfig(connection_string=connection_string, use_async_engine="+aiosqlite" in connection_string)
-    app = Starlite(route_handlers=[], plugins=[SQLAlchemyPlugin(config=config)])
-    request = RequestFactory().get()
-    session = config.create_db_session_dependency(state=app.state, scope=request.scope)
+    with create_test_client([], plugins=[SQLAlchemyPlugin(config=config)]) as client:
+        request = RequestFactory().get()
+        session = config.create_db_session_dependency(state=client.app.state, scope=request.scope)
     assert session
     assert request.scope[SESSION_SCOPE_KEY]  # type: ignore