Skip to content
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

Support (Inbuilt)[] - Value type missmatch with iterator over elements, equals equation (where param) codegen #50

Closed
yoroshikun opened this issue Apr 30, 2022 · 10 comments
Labels
bug Something isn't working

Comments

@yoroshikun
Copy link

yoroshikun commented Apr 30, 2022

First of all, thanks for working on this project!

I seem to be getting a pretty generic value type mismatch in the generated prisma -> rust codegen

a value of type `std::vec::Vec<prisma_client_rust::query_core::QueryValue>` cannot be built from an iterator over elements of type `prisma_client_rust::prisma_models::PrismaValue`

value of type `std::vec::Vec<prisma_client_rust::query_core::QueryValue>` cannot be built from `std::iter::Iterator<Item=prisma_client_rust::prisma_models::PrismaValue>`

help: the trait `std::iter::FromIterator<prisma_client_rust::prisma_models::PrismaValue>` is not implemented for `std::vec::Vec<prisma_client_rust::query_core::QueryValue>`rustc(E0277)

These errors pretty much exclusively appear under the equals equation something like

                Self::AtkLevelsEquals(value) => (
                    "ATKLevels".to_string(),
                    SerializedWhereValue::Object(vec![(
                        "equals".to_string(),
                        QueryValue::List(
                            value
                                .into_iter()
                                .map(|v| PrismaValue::Json(serde_json::to_string(&v).unwrap())) // <--- error here
                                .collect(),
                        ),
                    )]),
                ),

Edit

Almost immediately after posting this i noticed the correlation. Seems to happen on Inbuilt[] types such as String[] | Float[] | int[] etc
Have reflected it in the title

@yoroshikun yoroshikun changed the title Value type missmatch with iterator over elements, equals equation (where param) codegen Support Json[] - Value type missmatch with iterator over elements, equals equation (where param) codegen Apr 30, 2022
@yoroshikun yoroshikun changed the title Support Json[] - Value type missmatch with iterator over elements, equals equation (where param) codegen Support (Inbuilt)[] - Value type missmatch with iterator over elements, equals equation (where param) codegen Apr 30, 2022
@Brendonovich
Copy link
Owner

Ah, looks like I haven't added a .into() after the PrismaValue is constructed here.

@yoroshikun
Copy link
Author

Commit 7b103ca7e422d2d5a8935818407fc0023f1b3ab8 might be missing the into().
in other notes it also tends to not create a converter.

eg.

SetParam::SetAtkLevels(value) => ("ATKLevels".to_string(), converter), <-- this converter value is not made

@Brendonovich
Copy link
Owner

c1b97513b67e1b3c15d77d3cf120a50fd7a03ecd should fix the into not being added, what do you mean about the converter not being created?

@yoroshikun
Copy link
Author

this partially fixes it,

To explain more i get 2 errors for any schema item with the type [] that are inbuilt types (not other tables).

                SetParam::SetPossibleValuesFormat(value) => {
                    ("possibleValuesFormat".to_string(), converter) // <-- the converter here is not in scope, and i cannot find it, thinking it has just not been created?
                }
                SetParam::PushPossibleValuesFormat(value) => (
                    "possibleValuesFormat".to_string(),
                    QueryValue::Object(
                        vec![("push".to_string(), PrismaValue::String(value).into())] // <-- Getting error two below, type missmatch
                            .into_iter()
                            .collect(),
                    ),
                ),

Error 1:

cannot find value `converter` in this scope

 not found in this scoperustc(E0425)

Error 2:

mismatched types

expected struct `std::string::String`, found struct `std::vec::Vec`

note: expected struct `std::string::String`
      found struct `std::vec::Vec<std::string::String>`rustc(E0308)

@Brendonovich
Copy link
Owner

Error 1 is me being silly and forgetting a #

Error 2 is lists not being treated properly

Try b3c93e9eced80e259578e9a916531940c3876ad5

@yoroshikun
Copy link
Author

Much closer now,

Had to use commit 89df3982f80a68949f4f82d35a218838d56afc6b as b3c93e9eced80e259578e9a916531940c3876ad5 version bump panicked as it could not find the binary for my machine

Downloading https://prisma-photongo.s3-eu-west-1.amazonaws.com/prisma-cli-3.13.0-darwin.gz to /Users/yoroshi/Library/Caches/prisma/binaries/cli/3.13.0/prisma-cli-darwin
thread 'main' panicked at 'received code 404 Not Found from https://prisma-photongo.s3-eu-west-1.amazonaws.com/prisma-cli-3.13.0-darwin.gz', /Users/yoroshi/.cargo/git/checkouts/prisma-client-rust-fa967aa5ad0ec391/b3c93e9/cli/src/binaries/mod.rs:142:9

Still getting issues with Error 2 listed above, expecting non vec in generated code.
This time only for the "push" query.

@Brendonovich
Copy link
Owner

I haven't been able to replicate Error 2. Can you please provide a schema that generates the invalid code?

@Brendonovich Brendonovich added bug Something isn't working codegen labels May 1, 2022
@yoroshikun
Copy link
Author

Hi i was able to reproduce it with a modified example schema.
extra notes: these primitives are only available not using the sqlite adapter.

generator client {
  provider = "cargo prisma"
  output   = "../src/prisma.rs"
}

// Array primitives only available in postgresql
datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

model User {
  id String @id

  updatedAt   DateTime @default(now()) @updatedAt
  displayName String

  usernames String[] // These few lines generate the issues
  ids       Int[] // This one does too
  floats    Float[] // This one too
  bools     Boolean[] // This one too

  jsons Json[] // This one is fine

  posts Post[] // This is normal
}

model Post {
  id      String @id
  content String
  user    User   @relation(fields: [userId], references: [id])
  userId  String
}

@Brendonovich
Copy link
Owner

@yoroshikun I think I got it in 3cde8feb55a2efe7877ab57625c54f865ebf37c7

@yoroshikun
Copy link
Author

@Brendonovich This looks like it solved this issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants