question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Query wants a string when given an int, wants an int when given a string

See original GitHub issue

Bug description

With this query:

    const areaId = '1';
    const area = await db.area.findFirst({
      where: {
        id: areaId,
      },
      rejectOnNotFound: true,
    })
model Area {
  id                                        String                                      @id
  type                                      AreaType
  treeCanopy                                Float
  totalArea                                 Float
}

When the areaId variable is a string, I get

Invalid `prisma.area.findFirst()` invocation: Failed to validate the query: `Unable to match input value to any allowed input type for the field. Parse errors: [Query parsing/validation error at `Query.findFirstArea.where.AreaWhereInput.id`: Value types mismatch. Have: String("440030222021"), want: Object(IntFilter), Query parsing/validation error at `Query.findFirstArea.where.AreaWhereInput.id`: Value types mismatch. Have: String("440030222021"), want: Int]` at `Query.findFirstArea.where.AreaWhereInput.id`.

Okay, so let’s try an int. I change it to an int because it wants an int. Now, I get

Invalid `prisma.area.findFirst()` invocation: { where: { id: 440030222021 ~~~~~~~~~~~~ } } Argument id: Got invalid value 440030222021 on prisma.findFirstArea. Provided Int, expected StringFilter or String: type StringFilter { equals?: String in?: List<String> notIn?: List<String> lt?: String lte?: String gt?: String gte?: String contains?: String startsWith?: String endsWith?: String mode?: QueryMode not?: String | NestedStringFilter } type StringFilter { equals?: String in?: List<String> notIn?: List<String> lt?: String lte?: String gt?: String gte?: String contains?: String startsWith?: String endsWith?: String mode?: QueryMode not?: String | NestedStringFilter } .

So: when I have a string input to a query, it wants an int. When I have an int input, it wants a string. Frustrating.

How to reproduce

  • Load the given schema
  • Try the given query

Expected behavior

A string should be the input here.

Prisma information

  • Prisma/client 3.9.2
  • prisma 3.9.2

Environment & setup

  • OS: macOS
  • Database:PostgreSQL
  • Node.js version: 14.x

Prisma Version

3.9.2

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
tmcwcommented, Feb 16, 2022

This bug report includes the schema. The id column is a string column. If the column as an Int, then I would expect this to work with an integer value. As the issue describes, the query does not work with either integer or string values, and for each it requests the other.

0reactions
Jolg42commented, Sep 9, 2022

Could it be that id used to be an Int and somehow the schema used by the engine and the client are out of sync? Maybe a missing npx prisma generate or database migration?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Searching an int column on the basis of a string value
The query you have provided need to be optimized: First, using CAST(bkID AS NVARCHAR(MAX)) will affect the performance of the query, ...
Read more >
SQL Substring function overview - SQLShack
The T-SQL SUBSTRING function is very useful when you want to make sure that the string values returned from a query will be...
Read more >
Given two strings, find if first string is a Subsequence of second
The idea is simple, traverse both strings from one side to another side (say from rightmost character to leftmost). If we find a...
Read more >
i want to convert string into integer - Oracle Communities
This usually means that the given string is not in numeric format. What is it's value?
Read more >
Reference guide for expression functions - Azure Logic Apps
Given that the result is an object with property propertyName, get that property's value. ... int, Return the integer version for a string....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found