Repository: litestar-org/litestar

Issue:
Documentation: Unnecessary use of sync_to_thread=True
The following are calling object constructors with no I/O, so should be right to run sync.

https://github.com/litestar-org/litestar/blob/0d4fe01a9d361e09748f71aa7adf70672b97c822/docs/examples/contrib/sqlalchemy/sqlalchemy_sync_repository.py#L120

https://github.com/litestar-org/litestar/blob/0d4fe01a9d361e09748f71aa7adf70672b97c822/docs/examples/contrib/sqlalchemy/sqlalchemy_sync_repository.py#L154

https://github.com/litestar-org/litestar/blob/0d4fe01a9d361e09748f71aa7adf70672b97c822/docs/examples/contrib/sqlalchemy/sqlalchemy_sync_repository.py#L170



<!-- POLAR PLEDGE BADGE START -->
---
> [!NOTE]  
> While we are open for sponsoring on [GitHub Sponsors](https://github.com/sponsors/litestar-org/) and 
> [OpenCollective](https://opencollective.com/litestar), we also utilize [Polar.sh](https://polar.sh/) to engage in pledge-based sponsorship.
>
> Check out all issues funded or available for funding [on our Polar.sh Litestar dashboard](https://polar.sh/litestar-org)
> * If you would like to see an issue prioritized, make a pledge towards it!
> * We receive the pledge once the issue is completed & verified
> * This, along with engagement in the community, helps us know which features are a priority to our users.

<a href="https://polar.sh/litestar-org/litestar/issues/2508">
<picture>
  <source media="(prefers-color-scheme: dark)" srcset="https://polar.sh/api/github/litestar-org/litestar/issues/2508/pledge.svg?darkmode=1">
  <img alt="Fund with Polar" src="https://polar.sh/api/github/litestar-org/litestar/issues/2508/pledge.svg">
</picture>
</a>
<!-- POLAR PLEDGE BADGE END -->



Discussion:

Resolving patch:
diff --git a/docs/examples/contrib/sqlalchemy/plugins/sqlalchemy_sync_serialization_plugin.py b/docs/examples/contrib/sqlalchemy/plugins/sqlalchemy_sync_serialization_plugin.py
--- a/docs/examples/contrib/sqlalchemy/plugins/sqlalchemy_sync_serialization_plugin.py
+++ b/docs/examples/contrib/sqlalchemy/plugins/sqlalchemy_sync_serialization_plugin.py
@@ -21,7 +21,7 @@ class TodoItem(Base):
     done: Mapped[bool]
 
 
-@post("/", sync_to_thread=True)
+@post("/", sync_to_thread=False)
 def add_item(data: TodoItem) -> List[TodoItem]:
     return [data]
 
diff --git a/docs/examples/contrib/sqlalchemy/plugins/sqlalchemy_sync_serialization_plugin_marking_fields.py b/docs/examples/contrib/sqlalchemy/plugins/sqlalchemy_sync_serialization_plugin_marking_fields.py
--- a/docs/examples/contrib/sqlalchemy/plugins/sqlalchemy_sync_serialization_plugin_marking_fields.py
+++ b/docs/examples/contrib/sqlalchemy/plugins/sqlalchemy_sync_serialization_plugin_marking_fields.py
@@ -23,7 +23,7 @@ class TodoItem(Base):
     super_secret_value: Mapped[str] = mapped_column(info=dto_field("private"))
 
 
-@post("/", sync_to_thread=True)
+@post("/", sync_to_thread=False)
 def add_item(data: TodoItem) -> List[TodoItem]:
     data.super_secret_value = "This is a secret"
     return [data]
diff --git a/docs/examples/contrib/sqlalchemy/sqlalchemy_sync_repository.py b/docs/examples/contrib/sqlalchemy/sqlalchemy_sync_repository.py
--- a/docs/examples/contrib/sqlalchemy/sqlalchemy_sync_repository.py
+++ b/docs/examples/contrib/sqlalchemy/sqlalchemy_sync_repository.py
@@ -117,7 +117,7 @@ def provide_limit_offset_pagination(
 class AuthorController(Controller):
     """Author CRUD"""
 
-    dependencies = {"authors_repo": Provide(provide_authors_repo, sync_to_thread=True)}
+    dependencies = {"authors_repo": Provide(provide_authors_repo, sync_to_thread=False)}
 
     @get(path="/authors")
     def list_authors(
@@ -151,7 +151,7 @@ def create_author(
     # we override the authors_repo to use the version that joins the Books in
     @get(
         path="/authors/{author_id:uuid}",
-        dependencies={"authors_repo": Provide(provide_author_details_repo, sync_to_thread=True)},
+        dependencies={"authors_repo": Provide(provide_author_details_repo, sync_to_thread=False)},
     )
     def get_author(
         self,
@@ -167,7 +167,7 @@ def get_author(
 
     @patch(
         path="/authors/{author_id:uuid}",
-        dependencies={"authors_repo": Provide(provide_author_details_repo, sync_to_thread=True)},
+        dependencies={"authors_repo": Provide(provide_author_details_repo, sync_to_thread=False)},
     )
     def update_author(
         self,


Test patch: