Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upInsert is crashing while trying to insert an empty vector #384
Comments
This comment has been minimized.
|
I can reproduce this with: // diesel_tests/tests/insert.rs
#[test]
fn insert_records_empty_array() {
use schema::users::table as users;
let connection = connection();
let new_users: &[NewUser] = &[];
batch_insert(new_users, users, &connection);
let actual_users: Vec<User> = users.load::<User>(&connection).unwrap();
let expected_users: Vec<User> = vec![];
assert_eq!(expected_users, actual_users);
}This fails only with Postgres, as SQLite inserts multiple records one at a time in a simple for loop (that iterates zero times in this case). Edit: @sgrif I think I have an idea how to prevent this. Let me fiddle with it a bit, I'll send a PR. (No promise that it'll be elegant, though.) |
added a commit
to killercup/diesel
that referenced
this issue
Jul 29, 2016
added a commit
to killercup/diesel
that referenced
this issue
Aug 1, 2016
This comment has been minimized.
|
The same is happening for eq_any in select. #[test]
fn select_in_empty_array() {
use schema::users::dsl::*;
let connection = connection();
let user_ids:Vec<i32> = Vec::new();
let actual_users: Vec<User> = users
.filter(id.eq_any(&user_ids))
.load::<User>(&connection)
.unwrap();
let expected_users: Vec<User> = vec![];
assert_eq!(expected_users, actual_users);
}Backtrace:
|
added a commit
to weiznich/diesel
that referenced
this issue
Oct 15, 2016
weiznich
referenced this issue
Oct 15, 2016
Closed
Fix #384 (Invalid query on empty insert/select in) #480
sgrif
added this to the 0.9 milestone
Dec 3, 2016
added a commit
that referenced
this issue
Dec 5, 2016
sgrif
referenced this issue
Dec 5, 2016
Merged
Unify `InsertStatement` and `InsertQuery` into a single struct #518
added a commit
that referenced
this issue
Dec 5, 2016
added a commit
that referenced
this issue
Dec 5, 2016
added a commit
that referenced
this issue
Dec 5, 2016
added a commit
that referenced
this issue
Dec 5, 2016
added a commit
that referenced
this issue
Dec 5, 2016
sgrif
referenced this issue
Dec 5, 2016
Merged
Support batch insert on SQLite, fix inserting empty slices #519
sgrif
closed this
in
#519
Dec 5, 2016
This comment has been minimized.
|
#519 fixes only empty insert statements. |
This comment has been minimized.
|
Yup, I will have a fix for those shortly |
This comment has been minimized.
|
Opened #520 to track just in case |
sgrif
referenced this issue
Mar 13, 2017
Merged
Do less work in the inner loop of `assign_commits` #82
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
weiznich commentedJul 29, 2016
While trying to insert a dynamically generated vector of values diesel is crashing. It turns out the vector was empty in this special case.
I expect insert to handle the case of an empty vector and simply do nothing.
Backtrace: