Skip to content

Commit e4b45d6

Browse files
abr-egnqm3ster
authored andcommitted
RUST-1982 Fix aggregate with_type with explicit session (mongodb#1155)
1 parent 989e45b commit e4b45d6

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

src/action/aggregate.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ impl<'a, Session, T> Aggregate<'a, Session, T> {
128128
);
129129
}
130130

131-
impl<'a> Aggregate<'a, ImplicitSession> {
131+
impl<'a, T> Aggregate<'a, ImplicitSession, T> {
132132
/// Use the provided session when running the operation.
133133
pub fn session(
134134
self,
@@ -144,7 +144,7 @@ impl<'a> Aggregate<'a, ImplicitSession> {
144144
}
145145
}
146146

147-
impl<'a, Session> Aggregate<'a, Session, Document> {
147+
impl<'a, Session, T> Aggregate<'a, Session, T> {
148148
/// Use the provided type for the returned cursor.
149149
///
150150
/// ```rust
@@ -167,7 +167,7 @@ impl<'a, Session> Aggregate<'a, Session, Document> {
167167
/// # Ok(())
168168
/// # }
169169
/// ```
170-
pub fn with_type<T>(self) -> Aggregate<'a, Session, T> {
170+
pub fn with_type<U>(self) -> Aggregate<'a, Session, U> {
171171
Aggregate {
172172
target: self.target,
173173
pipeline: self.pipeline,
@@ -199,11 +199,11 @@ impl<'a, T> Action for Aggregate<'a, ImplicitSession, T> {
199199
}
200200
}
201201

202-
#[action_impl(sync = crate::sync::SessionCursor<Document>)]
203-
impl<'a> Action for Aggregate<'a, ExplicitSession<'a>> {
202+
#[action_impl(sync = crate::sync::SessionCursor<T>)]
203+
impl<'a, T> Action for Aggregate<'a, ExplicitSession<'a>, T> {
204204
type Future = AggregateSessionFuture;
205205

206-
async fn execute(mut self) -> Result<SessionCursor<Document>> {
206+
async fn execute(mut self) -> Result<SessionCursor<T>> {
207207
resolve_read_concern_with_session!(self.target, self.options, Some(&mut *self.session.0))?;
208208
resolve_write_concern_with_session!(self.target, self.options, Some(&mut *self.session.0))?;
209209
resolve_selection_criteria_with_session!(
@@ -218,8 +218,9 @@ impl<'a> Action for Aggregate<'a, ExplicitSession<'a>> {
218218
self.options,
219219
);
220220
let client = self.target.client();
221+
let session = self.session;
221222
client
222-
.execute_session_cursor_operation(aggregate, self.session.0)
223+
.execute_session_cursor_operation(aggregate, session.0)
223224
.await
224225
}
225226
}

src/test/db.rs

+20-1
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,26 @@ async fn aggregate_with_generics() {
404404
let _: Cursor<Document> = database.aggregate(pipeline.clone()).await.unwrap();
405405

406406
// Assert that data is properly deserialized when using with_type
407-
let mut cursor = database.aggregate(pipeline).with_type::<A>().await.unwrap();
407+
let mut cursor = database
408+
.aggregate(pipeline.clone())
409+
.with_type::<A>()
410+
.await
411+
.unwrap();
408412
assert!(cursor.advance().await.unwrap());
409413
assert_eq!(&cursor.deserialize_current().unwrap().str, "hi");
414+
415+
// Assert that `with_type` can be used with an explicit session.
416+
let mut session = client.start_session().await.unwrap();
417+
let _ = database
418+
.aggregate(pipeline.clone())
419+
.session(&mut session)
420+
.with_type::<A>()
421+
.await
422+
.unwrap();
423+
let _ = database
424+
.aggregate(pipeline.clone())
425+
.with_type::<A>()
426+
.session(&mut session)
427+
.await
428+
.unwrap();
410429
}

0 commit comments

Comments
 (0)