Cannot find type error in diesel generated model file?

I have a very odd "cannot find type" in scope error, E0412, in a file generated by diesel to model some tables in a local postgres cluster, specifically with "diesel_ext --model" while redirecting the output to a file. The error message suggests a remedy that is already present in the file! I can manually fix each error by prepending the type with "bigdecimal::" on each line, but that feels wrong and leaves me wondering why would that be needed in the presence of the "use bigdecimal::BigDecimal;" statement at the top of the file?! And I would like not to have to do that again in future if I need to regenerate the models. Many thanks to anyone with any insights.

error[E0412]: cannot find type `BigDecimal` in this scope
--> src/models_foo.rs:15:21
|
15 | pub month: BigDecimal,
| ^^^^^^^^^^ not found in this scope
|
help: consider importing one of these structs
|
11 + use crate::models_foo::BigDecimal;
|
11 + use bigdecimal::BigDecimal;
|

models_foo.rs starts off with:

// Generated by diesel_ext

#![allow(unused)]
#![allow(clippy::all)]

use chrono::NaiveDate;
use bigdecimal::BigDecimal;

pub mod foo {

#[derive(Queryable, Debug)]
pub struct MyTable {
    pub bar: Option<String>,
    pub baz: Option<String>,
    pub month: Option<BigDecimal>,
    pub id: i32,
}

Cargo.toml dependencies include:
[dependencies]
diesel = { version = "2.2.7", features = ["postgres", "64-column-tables","chrono","numeric","extras"] }
rust_decimal = "1.36"
rust_decimal_macros = "1.36"
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
thiserror = "1.0"
time = { version = "0.3", features = ["macros"] }
chrono = { version = "0.4.39", features = ["serde"] }
bigdecimal = { version = "0.4.7"}

Every module has its own namespace, even if it's not in its own file, so add or move the import inside that module.

1 Like

Many thanks. That worked. I am a relative newb to Rust and more so to Diesel. I find it odd. Shouldn't that have been handled properly by the diesel model generator?

One would hope so. You could file an issue with whatever tool generated the file (diesel_cli_ext?).