Skip to content

Commit a5342a9

Browse files
committed
Fix triggering a panic in the sqlite row cursor implementation
See diesel-rs/diesel#4115 for a fix of the underlying issue in diesel itself
1 parent 3844fb3 commit a5342a9

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/sync_connection_wrapper.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,17 @@ where
129129
let mut cache = <<<C as LoadConnection>::Row<'_, '_> as IntoOwnedRow<
130130
<C as Connection>::Backend,
131131
>>::Cache as Default>::default();
132-
conn.load(&query).map(|c| {
133-
c.map(|row| row.map(|r| IntoOwnedRow::into_owned(r, &mut cache)))
134-
.collect::<Vec<QueryResult<O>>>()
135-
})
132+
let cursor = conn.load(&query)?;
133+
134+
let size_hint = cursor.size_hint();
135+
let mut out = Vec::with_capacity(size_hint.1.unwrap_or(size_hint.0));
136+
// we use an explicit loop here to easily propagate possible errors
137+
// as early as possible
138+
for row in cursor {
139+
out.push(Ok(IntoOwnedRow::into_owned(row?, &mut cache)));
140+
}
141+
142+
Ok(out)
136143
})
137144
.map_ok(|rows| futures_util::stream::iter(rows).boxed())
138145
.boxed()

0 commit comments

Comments
 (0)