Skip to content

Commit 3ae2361

Browse files
committed
docs(flask): async-in-sync example should use the portal
Fixes #361
1 parent 05cc96f commit 3ae2361

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

advanced_alchemy/extensions/flask/extension.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from advanced_alchemy.exceptions import ImproperConfigurationError
1313
from advanced_alchemy.extensions.flask.cli import database_group
1414
from advanced_alchemy.extensions.flask.config import SQLAlchemyAsyncConfig, SQLAlchemySyncConfig
15-
from advanced_alchemy.utils.portals import PortalProvider
15+
from advanced_alchemy.utils.portals import Portal, PortalProvider
1616

1717
if TYPE_CHECKING:
1818
from flask import Flask
@@ -44,6 +44,11 @@ def __init__(
4444
if app is not None:
4545
self.init_app(app)
4646

47+
@property
48+
def portal(self) -> "Portal":
49+
"""Get the portal."""
50+
return self.portal_provider.portal
51+
4752
@property
4853
def config(self) -> "Sequence[Union[SQLAlchemyAsyncConfig, SQLAlchemySyncConfig]]":
4954
"""Get the SQLAlchemy configuration(s)."""

docs/usage/frameworks/flask.rst

+3-2
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ Advanced Alchemy supports async SQLAlchemy with Flask:
8686
8787
You can also safely use an AsyncSession in your routes within a sync context.
8888

89+
8990
.. warning::
9091

9192
This is experimental and may change in the future.
@@ -94,8 +95,8 @@ You can also safely use an AsyncSession in your routes within a sync context.
9495
9596
@app.route("/users")
9697
def list_users():
97-
session = alchemy.get_sync_session()
98-
users = session.execute(select(User))
98+
session = alchemy.get_async_session()
99+
users = alchemy.portal.call(session.execute, select(User))
99100
return {"users": [user.dict() for user in users.scalars()]}
100101
101102
Configuration

0 commit comments

Comments
 (0)