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
@@ -193,7 +193,7 @@ 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._base_select(**kwargs)
+            statement = kwargs.pop("base_select", self.statement)
             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)
@@ -213,7 +213,7 @@ async def get_one(self, **kwargs: Any) -> ModelT:
             NotFoundError: If no instance found identified by `item_id`.
         """
         with wrap_sqlalchemy_exception():
-            statement = self._base_select(**kwargs)
+            statement = kwargs.pop("base_select", self.statement)
             statement = self._filter_select_by_kwargs(statement=statement, **kwargs)
             instance = (await self._execute(statement)).scalar_one_or_none()
             instance = self.check_not_found(instance)
@@ -230,12 +230,12 @@ async def get_one_or_none(self, **kwargs: Any) -> ModelT | None:
             The retrieved instance or None
         """
         with wrap_sqlalchemy_exception():
-            statement = self._base_select(**kwargs)
+            statement = kwargs.pop("base_select", self.statement)
             statement = self._filter_select_by_kwargs(statement=statement, **kwargs)
             instance = (await self._execute(statement)).scalar_one_or_none()
             if instance:
                 self.session.expunge(instance)
-            return instance
+            return instance  # type: ignore
 
     async def get_or_create(self, **kwargs: Any) -> tuple[ModelT, bool]:
         """Get instance identified by ``kwargs`` or create if it doesn't exist.
@@ -261,7 +261,7 @@ async def count(self, *filters: FilterTypes, **kwargs: Any) -> int:
         Returns:
             Count of records returned by query, ignoring pagination.
         """
-        statement = self._base_select(**kwargs)
+        statement = kwargs.pop("base_select", self.statement)
         statement = statement.with_only_columns(
             sql_func.count(
                 self.model_type.id,  # type:ignore[attr-defined]
@@ -348,7 +348,7 @@ async def list_and_count(
         Returns:
             Count of records returned by query, ignoring pagination.
         """
-        statement = self._base_select(**kwargs)
+        statement = kwargs.pop("base_select", self.statement)
         statement = statement.add_columns(
             over(
                 sql_func.count(
@@ -379,7 +379,7 @@ async def list(self, *filters: FilterTypes, **kwargs: Any) -> list[ModelT]:
         Returns:
             The list of instances, after filtering applied.
         """
-        statement = self._base_select(**kwargs)
+        statement = kwargs.pop("base_select", self.statement)
         statement = self._apply_filters(*filters, statement=statement)
         statement = self._filter_select_by_kwargs(statement, **kwargs)
 
@@ -516,6 +516,3 @@ 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:
diff --git a/tests/contrib/sqlalchemy/repository/test_sqlalchemy_aiosqlite.py b/tests/contrib/sqlalchemy/repository/test_sqlalchemy_aiosqlite.py
--- a/tests/contrib/sqlalchemy/repository/test_sqlalchemy_aiosqlite.py
+++ b/tests/contrib/sqlalchemy/repository/test_sqlalchemy_aiosqlite.py
@@ -8,7 +8,7 @@
 from uuid import UUID, uuid4
 
 import pytest
-from sqlalchemy import NullPool, insert
+from sqlalchemy import NullPool, insert, select
 from sqlalchemy.ext.asyncio import (
     AsyncEngine,
     AsyncSession,
@@ -147,6 +147,20 @@ async def test_repo_count_method(author_repo: AuthorRepository) -> None:
     assert await author_repo.count() == 2
 
 
+async def test_repo_base_select_override(author_repo: AuthorRepository) -> None:
+    """Test SQLALchemy base select override with sqlite.
+
+    Args:
+        author_repo (AuthorRepository): The author mock repository
+    """
+    all_count = await author_repo.count()
+    filtered_count = await author_repo.count(
+        base_select=select(Author).where(Author.id == UUID("5ef29f3c-3560-4d15-ba6b-a2e5c721e4d2"))
+    )
+    assert all_count == 2
+    assert filtered_count == 1
+
+
 async def test_repo_list_and_count_method(raw_authors: list[dict[str, Any]], author_repo: AuthorRepository) -> None:
     """Test SQLALchemy list with count in sqlite.