From 6ee069f5c89ca32db6c77ee0a76f3ffa5e50ca41 Mon Sep 17 00:00:00 2001 From: Abraham Egnor Date: Thu, 27 Jun 2024 11:05:29 -0400 Subject: [PATCH 1/2] RUST-1982 Fix aggregate with_type with explicit session --- src/action/aggregate.rs | 12 ++++++------ src/test/db.rs | 21 ++++++++++++++++++++- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/action/aggregate.rs b/src/action/aggregate.rs index 785f8619b..2eb18d3b5 100644 --- a/src/action/aggregate.rs +++ b/src/action/aggregate.rs @@ -128,7 +128,7 @@ impl<'a, Session, T> Aggregate<'a, Session, T> { ); } -impl<'a> Aggregate<'a, ImplicitSession> { +impl<'a, T> Aggregate<'a, ImplicitSession, T> { /// Use the provided session when running the operation. pub fn session( self, @@ -144,7 +144,7 @@ impl<'a> Aggregate<'a, ImplicitSession> { } } -impl<'a, Session> Aggregate<'a, Session, Document> { +impl<'a, Session, T> Aggregate<'a, Session, T> { /// Use the provided type for the returned cursor. /// /// ```rust @@ -167,7 +167,7 @@ impl<'a, Session> Aggregate<'a, Session, Document> { /// # Ok(()) /// # } /// ``` - pub fn with_type(self) -> Aggregate<'a, Session, T> { + pub fn with_type(self) -> Aggregate<'a, Session, U> { Aggregate { target: self.target, pipeline: self.pipeline, @@ -199,11 +199,11 @@ impl<'a, T> Action for Aggregate<'a, ImplicitSession, T> { } } -#[action_impl(sync = crate::sync::SessionCursor)] -impl<'a> Action for Aggregate<'a, ExplicitSession<'a>> { +#[action_impl(sync = crate::sync::SessionCursor)] +impl<'a, T> Action for Aggregate<'a, ExplicitSession<'a>, T> { type Future = AggregateSessionFuture; - async fn execute(mut self) -> Result> { + async fn execute(mut self) -> Result> { resolve_read_concern_with_session!(self.target, self.options, Some(&mut *self.session.0))?; resolve_write_concern_with_session!(self.target, self.options, Some(&mut *self.session.0))?; resolve_selection_criteria_with_session!( diff --git a/src/test/db.rs b/src/test/db.rs index 01bfe33c2..2cc91abd7 100644 --- a/src/test/db.rs +++ b/src/test/db.rs @@ -404,7 +404,26 @@ async fn aggregate_with_generics() { let _: Cursor = database.aggregate(pipeline.clone()).await.unwrap(); // Assert that data is properly deserialized when using with_type - let mut cursor = database.aggregate(pipeline).with_type::().await.unwrap(); + let mut cursor = database + .aggregate(pipeline.clone()) + .with_type::() + .await + .unwrap(); assert!(cursor.advance().await.unwrap()); assert_eq!(&cursor.deserialize_current().unwrap().str, "hi"); + + // Assert that `with_type` can be used with an explicit session. + let mut session = client.start_session().await.unwrap(); + let _ = database + .aggregate(pipeline.clone()) + .session(&mut session) + .with_type::() + .await + .unwrap(); + let _ = database + .aggregate(pipeline.clone()) + .with_type::() + .session(&mut session) + .await + .unwrap(); } From dd988d13787e2c7e6eebe4efd0ad247323e995d2 Mon Sep 17 00:00:00 2001 From: Abraham Egnor Date: Thu, 27 Jun 2024 12:12:30 -0400 Subject: [PATCH 2/2] fix msrv compilation --- src/action/aggregate.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/action/aggregate.rs b/src/action/aggregate.rs index 2eb18d3b5..2c419829a 100644 --- a/src/action/aggregate.rs +++ b/src/action/aggregate.rs @@ -218,8 +218,9 @@ impl<'a, T> Action for Aggregate<'a, ExplicitSession<'a>, T> { self.options, ); let client = self.target.client(); + let session = self.session; client - .execute_session_cursor_operation(aggregate, self.session.0) + .execute_session_cursor_operation(aggregate, session.0) .await } }