Brendonovich / prisma-client-rust

Type-safe database access for Rust
https://prisma.brendonovich.dev
Apache License 2.0
1.8k stars 104 forks source link

Failure to correctly qualify enums in generated code #199

Closed codemaster138 closed 1 year ago

codemaster138 commented 1 year ago

Problem Description

When using enums, the generated prisma.rs file references the enums only with their name rather than a fully qualified identifier, leading to errors such as:

error[E0412]: cannot find type `MyEnum` in this scope
   --> src/prisma.rs:XXX:XX
    |
XXX |       Not(MyEnum),
    |           ^^^^^^^ not found in this scope
    |
help: consider importing this enum
    |
XXX |     use crate::prisma::MyEnum;
    |

To Reproduce

Steps to reproduce the behavior:

  1. Clone codemaster138/prisma-client-rust-repro
  2. Run cargo prisma generate
  3. Run cargo check

Expected Behavior

The code generator should either:

Environment

Additional Context

This seems like an issue that should almost definitely have been caught by now, so, if you can't reproduce this, the possibility of being an M1 platform bug should be investigated...

Brendonovich commented 1 year ago

Similar to #197. Will get on these ASAP for 1.6.4.

codemaster138 commented 1 year ago

Oops, hadn't seen that issue. Sorry!

Brendonovich commented 1 year ago

No worries, this problem is a bit different so it's ok. Really appreciate the detailed issue haha.

codemaster138 commented 1 year ago

@Brendonovich I'm not sure whether this is a clean fix, but for the example I provided, changing read_filters.rs:17 like this:

-                quote!(#variant_name(#typ)),
+                quote!(#variant_name(super::super::#typ)),

might help...?

Brendonovich commented 1 year ago

@codemaster138 I think that will break primitive types (which is what I made the read filter change for). I'll need to check whether the type is a builtin or custom type.

Brendonovich commented 1 year ago

On second look, this is actually a duplicate. Am working on it rn.