diesel-rs/diesel

AllColumns pattern isn't compatible with BoxedQuery pattern

Open

#1979 opened on Feb 6, 2019

View on GitHub
 (3 comments) (0 reactions) (0 assignees)Rust (12,054 stars) (1,003 forks)batch import
documentationgood first issuehelp wanted

Description

Possibly related: #1435

Setup

Versions

  • Rust: rustc 1.32.0 (9fda7c223 2019-01-16), edition = "2018"
  • Diesel: 1.4.1
  • Database: postgres 10.5
  • Operating System: macOS Mojave

Feature Flags

  • diesel: ["postgres"]

Problem Description

What are you trying to accomplish?

In crates.io's code, I'm trying to add a column to our versions table that exists in the database but is never selected by the Queryable model, using the AllColumns pattern described in the composing applications diesel guide that we've successfully used for the crates table.

The problem is there's a set of functions that return versions::BoxedQuery, using the BoxedQuery pattern described in the same guide, and those functions stop compiling when I add the AllColumn types.

What is the expected output?

Successful compilation

What is the actual output?

error[E0277]: the trait bound `(i32, i32, std::string::String): diesel::Queryable<(diesel::sql_types::Integer, diesel::sql_types::Integer, diesel::sql_types::Text, diesel::sql_types::Nullable<diesel::sql_types::Text>), _>` is not satisfied
   --> src/main.rs:123:47
    |
123 |     let versions = first_crate.all_versions().load::<Version>(&conn).unwrap();
    |                                               ^^^^ the trait `diesel::Queryable<(diesel::sql_types::Integer, diesel::sql_types::Integer, diesel::sql_types::Text, diesel::sql_types::Nullable<diesel::sql_types::Text>), _>` is not implemented for `(i32, i32, std::string::String)`
    |
    = help: the following implementations were found:
              <(A, B, C) as diesel::Queryable<(SA, SB, SC), __DB>>
              <(A, B, C) as diesel::Queryable<diesel::sql_types::Record<(SA, SB, SC)>, diesel::pg::Pg>>
    = note: required because of the requirements on the impl of `diesel::Queryable<(diesel::sql_types::Integer, diesel::sql_types::Integer, diesel::sql_types::Text, diesel::sql_types::Nullable<diesel::sql_types::Text>), _>` for `version::Version`
    = note: required because of the requirements on the impl of `diesel::query_dsl::LoadQuery<_, version::Version>` for `diesel::query_builder::BoxedSelectStatement<'_, (diesel::sql_types::Integer, diesel::sql_types::Integer, diesel::sql_types::Text, diesel::sql_types::Nullable<diesel::sql_types::Text>), schema::versions::table, diesel::pg::Pg>`

Are you seeing any additional errors?

No

Steps to reproduce

I've extracted a minimal example into this repo: https://github.com/carols10cents/diesel-mvce

At this commit, with the call to the all_versions function commented out, the code compiles and works as I expect.

At this commit, which uncomments out the call to the all_versions function, I get the compilation error shown above.

Checklist

  • I have already looked over the issue tracker for similar issues.
  • This issue can be reproduced on Rust's stable channel. (Your issue will be closed if this is not the case)

Contributor guide