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/contrib/sqlalchemy/repository.py b/starlite/contrib/sqlalchemy/repository.py
--- a/starlite/contrib/sqlalchemy/repository.py
+++ b/starlite/contrib/sqlalchemy/repository.py
@@ -4,7 +4,7 @@
 from contextlib import contextmanager
 from typing import TYPE_CHECKING, Any, Generic, Literal, Tuple, TypeVar, cast
 
-from sqlalchemy import delete, over, select, text, update
+from sqlalchemy import Select, delete, over, select, text, update
 from sqlalchemy import func as sql_func
 from sqlalchemy.exc import IntegrityError, SQLAlchemyError
 
@@ -20,7 +20,6 @@
     from collections import abc
     from datetime import datetime
 
-    from sqlalchemy import Select
     from sqlalchemy.engine import Result
     from sqlalchemy.ext.asyncio import AsyncSession
 
@@ -76,7 +75,7 @@ def __init__(
         """
         super().__init__(**kwargs)
         self.session = session
-        self.statement = base_select or select(self.model_type)
+        self.statement = base_select if base_select is not None else select(self.model_type)
 
     async def add(self, data: ModelT) -> ModelT:
         """Add `data` to the collection.
@@ -194,7 +193,8 @@ async def get(self, item_id: Any, **kwargs: Any) -> ModelT:
             NotFoundError: If no instance found identified by `item_id`.
         """
         with wrap_sqlalchemy_exception():
-            statement = self._filter_select_by_kwargs(statement=self.statement, **{self.id_attribute: item_id})
+            statement = self._base_select(**kwargs)
+            statement = self._filter_select_by_kwargs(statement=statement, **{self.id_attribute: item_id})
             instance = (await self._execute(statement)).scalar_one_or_none()
             instance = self.check_not_found(instance)
             self.session.expunge(instance)
@@ -213,7 +213,8 @@ async def get_one(self, **kwargs: Any) -> ModelT:
             NotFoundError: If no instance found identified by `item_id`.
         """
         with wrap_sqlalchemy_exception():
-            statement = self._filter_select_by_kwargs(statement=self.statement, **kwargs)
+            statement = self._base_select(**kwargs)
+            statement = self._filter_select_by_kwargs(statement=statement, **kwargs)
             instance = (await self._execute(statement)).scalar_one_or_none()
             instance = self.check_not_found(instance)
             self.session.expunge(instance)
@@ -229,7 +230,8 @@ async def get_one_or_none(self, **kwargs: Any) -> ModelT | None:
             The retrieved instance or None
         """
         with wrap_sqlalchemy_exception():
-            statement = self._filter_select_by_kwargs(statement=self.statement, **kwargs)
+            statement = self._base_select(**kwargs)
+            statement = self._filter_select_by_kwargs(statement=statement, **kwargs)
             instance = (await self._execute(statement)).scalar_one_or_none()
             if instance:
                 self.session.expunge(instance)
@@ -259,7 +261,8 @@ async def count(self, *filters: FilterTypes, **kwargs: Any) -> int:
         Returns:
             Count of records returned by query, ignoring pagination.
         """
-        statement = self.statement.with_only_columns(
+        statement = self._base_select(**kwargs)
+        statement = statement.with_only_columns(
             sql_func.count(
                 self.model_type.id,  # type:ignore[attr-defined]
             ),
@@ -345,7 +348,8 @@ async def list_and_count(
         Returns:
             Count of records returned by query, ignoring pagination.
         """
-        statement = self.statement.add_columns(
+        statement = self._base_select(**kwargs)
+        statement = statement.add_columns(
             over(
                 sql_func.count(
                     self.model_type.id,  # type:ignore[attr-defined]
@@ -375,7 +379,8 @@ async def list(self, *filters: FilterTypes, **kwargs: Any) -> list[ModelT]:
         Returns:
             The list of instances, after filtering applied.
         """
-        statement = self._apply_filters(*filters, statement=self.statement)
+        statement = self._base_select(**kwargs)
+        statement = self._apply_filters(*filters, statement=statement)
         statement = self._filter_select_by_kwargs(statement, **kwargs)
 
         with wrap_sqlalchemy_exception():
@@ -511,3 +516,6 @@ def _filter_select_by_kwargs(self, statement: SelectT, **kwargs: Any) -> SelectT
         for key, val in kwargs.items():
             statement = statement.where(getattr(self.model_type, key) == val)
         return statement
+
+    def _base_select(self, **kwargs: Any) -> Select[tuple[ModelT]]:
+        return kwargs.pop("base_select", self.statement)


Test patch: