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

Cannot SELECT from schemas other than 'public' even though generated SQL output works #1411

Closed
dev10 opened this Issue Dec 18, 2017 · 1 comment

Comments

Projects
None yet
1 participant
@dev10

dev10 commented Dec 18, 2017

Setup

Versions

  • Rust: nightly 2017-11-29
  • Diesel: 0.99 and 1.0.0-beta1
  • Database: PostgreSQL 10
  • Operating System macOS 10.12.6

Feature Flags

  • diesel: postgres, uuid
  • diesel_infer_schema: postgres

Problem Description

When trying to load data from from a schema other than the default public, v2 in my case, I get a DatabaseError.
When using the output from debug_query in PostgreSQL directly, it works fine. When querying using both a filtered and unfiltered load call, it fails with a DatabaseError.
Looking at the output of the error, it is quoting the entire "schema.table" instead of "schema"."table"

What are you trying to accomplish?

Load data from domain_registration table located in a schema other than the default public, v2 in my case.

What is the expected output?

Data from domain_registration table in v2 schema

What is the actual output?

Working query from debug_query:
SELECT "v2"."domain_registration"."domain", "v2"."domain_registration"."branch_guids" FROM "v2"."domain_registration" WHERE "v2"."domain_registration"."domain" = $1 -- binds: ["a_domain"]

Get error when actually run:
thread 'db::tests::can_get_all_data_from_schema' panicked at 'Failed to get results: DatabaseError(__Unknown, "relation "v2.domain_registration" does not exist")',

Are you seeing any additional errors?

stack backtrace:
   0:        0x10c5232bb - std::sys::unix::backtrace::tracing::imp::unwind_backtrace::h1151d91b8c159af8
   1:        0x10c51c03e - std::sys_common::backtrace::print::h67f8549b8891a6f1
   2:        0x10c524590 - _ZN3std9panicking12default_hook28_$u7b$$u7b$closure$u7d$$u7d$17h87a5c1996ce480feE.llvm.A7B5D2F1
   3:        0x10c5242f0 - _ZN3std9panicking12default_hook17h99b58f5ba7dd5ae4E.llvm.A7B5D2F1
   4:        0x10c5249f6 - std::panicking::rust_panic_with_hook::ha6e35eca651b52eb
   5:        0x10c52484e - _ZN3std9panicking11begin_panic17h61c0da3081a85bacE.llvm.A7B5D2F1
   6:        0x10c5247a3 - std::panicking::begin_panic_fmt::h7cc1795e4e981773
   7:        0x10c12c429 - app_name::db::tests::can_get_all_data_from_schema::ha84eaf6242f39719
   8:        0x10c2da801 - _ZN42_$LT$F$u20$as$u20$test..FnBox$LT$T$GT$$GT$8call_box17hacfaa0c3eb7c76e0E.llvm.8136107D
   9:        0x10c53b85e - __rust_maybe_catch_panic
  10:        0x10c2caf00 - std::sys_common::backtrace::__rust_begin_short_backtrace::hbc80a456d2b61ca2
  11:        0x10c2d06f7 - _ZN3std9panicking3try7do_call17h34892342000d4cf1E.llvm.CC792E6E
  12:        0x10c53b85e - __rust_maybe_catch_panic
  13:        0x10c2e6cb1 - _ZN50_$LT$F$u20$as$u20$alloc..boxed..FnBox$LT$A$GT$$GT$8call_box17h11b0f6bfb9cd6ad1E.llvm.70378DDD
  14:        0x10c51ea67 - std::sys_common::thread::start_thread::h911e223acc8911b3
  15:        0x10c52bb38 - _ZN3std3sys4unix6thread6Thread3new12thread_start17h0b2f1db353daeea2E.llvm.6415E5CA
  16:     0x7fffc124d93a - _pthread_body
  17:     0x7fffc124d886 - _pthread_start

Steps to reproduce

table.rs:

pub mod v2 {
    table! {
        v2.domain_registration (domain) {
            domain -> Text,
            branch_guids -> Array<Uuid>,
        }
    }
}

models.rs:

#[derive(Queryable)]
pub struct DomainRegistration {
    pub domain: String,
    pub branch_guids: Vec<Uuid>,
}

db.rs:

    #[test]
    fn can_get_all_data_from_schema() {
        use diesel::prelude::*;

        use models::*;
        use table::v2::domain_registration;
        use table::v2::domain_registration::dsl::*;

        let pool = init_pool();
        let conn = pool.get().unwrap();

        match domain_registration::table.load::<DomainRegistration>(&*conn) {
            Ok(results) => {
                for d in results {
                    println!("Domain: {:?}", d.domain);
                }
            },
            Err(e) => panic!("Failed to get results: {:?}", e)
        }
    }

Checklist

  • I have already looked over the issue tracker for similar issues.
@dev10

This comment has been minimized.

dev10 commented Dec 18, 2017

Looks like the PostgreSQL DatabaseError output was misleading. It was connected to the wrong database

@dev10 dev10 closed this Dec 18, 2017

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