New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

select query loads data incorrectly if model is 'out of order' #421

Closed
fuchsnj opened this Issue Aug 28, 2016 · 7 comments

Comments

Projects
None yet
7 participants
@fuchsnj

fuchsnj commented Aug 28, 2016

Model looks like this:

#[derive(Queryable, Debug)]
#[insertable_into(users)]
pub struct Model{
    pub id: String,
    pub username: String,
    pub email: String,
    pub password: String
}

And up.sql looks like this

CREATE TABLE users
(
  id text NOT NULL,
  username text NOT NULL,
  password text NOT NULL,
  email text NOT NULL,
  CONSTRAINT users_pkey PRIMARY KEY (id),
  CONSTRAINT users_username_key UNIQUE (username),
  CONSTRAINT users_email_key UNIQUE (email)
)

When I select a user, email and password are swapped

let mut result = try!(users::dsl::users.filter(users::dsl::username.eq(username))
    .limit(1)
    .load::<Model>(&establish_connection())
);
@theduke

This comment has been minimized.

Contributor

theduke commented Dec 22, 2016

Stumbled over this too.

Quite a big bug / gotcha.

Any fix upcoming?

@TedDriggs

This comment has been minimized.

TedDriggs commented Feb 3, 2017

I got bitten by this, and also discovered that I had to blow away my target directory after fixing the up.sql file for the Rust struct to work as expected.

@zhangsoledad

This comment has been minimized.

zhangsoledad commented Apr 25, 2017

This is big big gotcha!!

@theduke

This comment has been minimized.

Contributor

theduke commented Apr 25, 2017

Could there be a compile time test/lint for this?

@killercup

This comment has been minimized.

Member

killercup commented Apr 25, 2017

Could there be a compile time test/lint for this?

See #573

@willmurphyscode

This comment has been minimized.

Contributor

willmurphyscode commented Sep 27, 2017

I'd like to help with this, but I'm not sure exactly how to get started. @sgrif mentions in #573 that we don't want to talk to the database when running the linter. Should this linter inspect the structs and the .sql files in the migrations? If so, will the linter need to find both CREATE TABLE and ALTER TABLE calls and figure out what the table currently looks like?

@sgrif

This comment has been minimized.

Member

sgrif commented Dec 16, 2017

I think this issue has been addressed as much as it can be.

We now have QueryableByName for use with sql_query, since order specifics are painful when writing the query by hand. I've tried to make the fact that Queryable cares about order as clear on this as I can be in the documentation. The only other thing we can do for this a lint, which is covered in #573.

@sgrif sgrif closed this Dec 16, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment