Skip to content

Commit 73cb007

Browse files
committed
fix function_info clone issue
1 parent 443a2c8 commit 73cb007

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

src/routers/middleware_router.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use std::sync::RwLock;
33

44
use anyhow::{Context, Error, Result};
55
use matchit::Router as MatchItRouter;
6-
use pyo3::types::PyAny;
76
use pyo3::{Bound, Python};
87

98
use crate::routers::Router;
@@ -84,11 +83,15 @@ impl MiddlewareRouter {
8483
}
8584

8685
pub fn get_global_middlewares(&self, middleware_type: &MiddlewareType) -> Vec<FunctionInfo> {
87-
self.globals
88-
.get(middleware_type)
89-
.unwrap()
90-
.read()
91-
.unwrap()
92-
.to_vec()
86+
Python::with_gil(|py| {
87+
self.globals
88+
.get(middleware_type)
89+
.unwrap()
90+
.read()
91+
.unwrap()
92+
.iter()
93+
.map(|fi| fi.clone_with_gil(py))
94+
.collect()
95+
})
9396
}
9497
}

src/types/function_info.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,14 @@ impl FunctionInfo {
5757
kwargs,
5858
}
5959
}
60+
61+
pub fn clone_with_gil(&self, py: Python) -> Self {
62+
Self {
63+
handler: self.handler.clone_ref(py),
64+
is_async: self.is_async,
65+
number_of_params: self.number_of_params,
66+
args: self.args.clone_ref(py),
67+
kwargs: self.kwargs.clone_ref(py),
68+
}
69+
}
6070
}

0 commit comments

Comments
 (0)