Skip to content

Commit eb3a5ad

Browse files
committed
update afterware arg parsing
1 parent 6ffefe2 commit eb3a5ad

File tree

2 files changed

+62
-8
lines changed

2 files changed

+62
-8
lines changed

fasthtml/core.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -619,8 +619,8 @@ async def _f(req):
619619
req.body_wrap = body_wrap
620620
if not resp: resp = await _wrap_call(f, req, sig.parameters)
621621
for a in self.after:
622-
_,*wreq = await _wrap_req(req, _params(a))
623-
nr = a(resp, *wreq)
622+
wreq = await _wrap_req(req, _params(a))
623+
nr = a(*wreq.values())
624624
if nr: resp = nr
625625
return _resp(req, resp, sig.return_annotation)
626626
return _f

nbs/api/00_core.ipynb

Lines changed: 60 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@
131131
{
132132
"data": {
133133
"text/plain": [
134-
"datetime.datetime(2025, 8, 22, 14, 0)"
134+
"datetime.datetime(2025, 9, 11, 14, 0)"
135135
]
136136
},
137137
"execution_count": null,
@@ -1724,8 +1724,8 @@
17241724
" req.body_wrap = body_wrap\n",
17251725
" if not resp: resp = await _wrap_call(f, req, sig.parameters)\n",
17261726
" for a in self.after:\n",
1727-
" _,*wreq = await _wrap_req(req, _params(a))\n",
1728-
" nr = a(resp, *wreq)\n",
1727+
" wreq = await _wrap_req(req, _params(a))\n",
1728+
" nr = a(*wreq.values())\n",
17291729
" if nr: resp = nr\n",
17301730
" return _resp(req, resp, sig.return_annotation)\n",
17311731
" return _f"
@@ -2878,13 +2878,13 @@
28782878
"name": "stdout",
28792879
"output_type": "stream",
28802880
"text": [
2881-
"Set to 2025-08-22 01:21:53.772537\n"
2881+
"Set to 2025-09-11 09:53:37.344743\n"
28822882
]
28832883
},
28842884
{
28852885
"data": {
28862886
"text/plain": [
2887-
"'Session time: 2025-08-22 01:21:53.772537'"
2887+
"'Session time: 2025-09-11 09:53:37.344743'"
28882888
]
28892889
},
28902890
"execution_count": null,
@@ -3055,6 +3055,60 @@
30553055
"test_eq(cli.get('/locked', auth=(\"testuser\",\"spycraft\")).text, 'Hello, testuser')"
30563056
]
30573057
},
3058+
{
3059+
"cell_type": "markdown",
3060+
"id": "967001f3",
3061+
"metadata": {},
3062+
"source": [
3063+
"Check that afterware like toasts are called correctly."
3064+
]
3065+
},
3066+
{
3067+
"cell_type": "code",
3068+
"execution_count": null,
3069+
"id": "09a5fb96",
3070+
"metadata": {},
3071+
"outputs": [],
3072+
"source": [
3073+
"from fasthtml.toaster import *"
3074+
]
3075+
},
3076+
{
3077+
"cell_type": "code",
3078+
"execution_count": null,
3079+
"id": "c7500555",
3080+
"metadata": {},
3081+
"outputs": [],
3082+
"source": [
3083+
"app,cli,rt = get_cli(FastHTML())\n",
3084+
"setup_toasts(app)\n",
3085+
"\n",
3086+
"@rt(\"/\")\n",
3087+
"def index(sess): \n",
3088+
" add_toast(sess, \"Successful Page Load!\", \"success\")\n",
3089+
" return P(\"I love toast!\")"
3090+
]
3091+
},
3092+
{
3093+
"cell_type": "code",
3094+
"execution_count": null,
3095+
"id": "0ddf5964",
3096+
"metadata": {},
3097+
"outputs": [],
3098+
"source": [
3099+
"r = cli.get('/')"
3100+
]
3101+
},
3102+
{
3103+
"cell_type": "code",
3104+
"execution_count": null,
3105+
"id": "86386f6d",
3106+
"metadata": {},
3107+
"outputs": [],
3108+
"source": [
3109+
"assert 'Successful Page Load!' in r.text"
3110+
]
3111+
},
30583112
{
30593113
"cell_type": "markdown",
30603114
"id": "6a014add",
@@ -3423,7 +3477,7 @@
34233477
{
34243478
"data": {
34253479
"text/plain": [
3426-
"'Cookie was set at time 01:21:59.994611'"
3480+
"'Cookie was set at time 09:53:37.455388'"
34273481
]
34283482
},
34293483
"execution_count": null,

0 commit comments

Comments
 (0)