File tree Expand file tree Collapse file tree 2 files changed +7
-7
lines changed Expand file tree Collapse file tree 2 files changed +7
-7
lines changed Original file line number Diff line number Diff line change @@ -517,7 +517,9 @@ where
517
517
/// The query is truncated to the initial fragment provided to [`new()`][Self::new] and
518
518
/// the bind arguments are reset.
519
519
pub fn reset ( & mut self ) -> & mut Self {
520
- let query: & mut String = Arc :: get_mut ( & mut self . query ) . expect ( ERROR ) ;
520
+ // Someone can hold onto a clone of `self.query` by calling build and not executing the
521
+ // query. To avoid panicking here we might as well allocate a new `String`.
522
+ let query: & mut String = Arc :: make_mut ( & mut self . query ) ;
521
523
query. truncate ( self . init_len ) ;
522
524
self . arguments = Some ( Default :: default ( ) ) ;
523
525
Original file line number Diff line number Diff line change @@ -79,12 +79,10 @@ fn test_reset() {
79
79
fn test_query_builder_reuse ( ) {
80
80
let mut qb: QueryBuilder < ' _ , Postgres > = QueryBuilder :: new ( "" ) ;
81
81
82
- {
83
- let _query = qb
84
- . push ( "SELECT * FROM users WHERE id = " )
85
- . push_bind ( 42i32 )
86
- . build ( ) ;
87
- }
82
+ let _query = qb
83
+ . push ( "SELECT * FROM users WHERE id = " )
84
+ . push_bind ( 42i32 )
85
+ . build ( ) ;
88
86
89
87
qb. reset ( ) ;
90
88
You can’t perform that action at this time.
0 commit comments