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.

Upsert error on MySQL: `Query ... is required to return data, but found no record(s)` when you try to write an overflowing unsigned int

See original GitHub issue

Bug description

I see the Query ... is required to return data, but found no record(s) error.

Similar in manifestation to #12783, but, this time without having a Date involved in the primary or unique keys.

However, the entity does have two date fields.

I don’t have approval to share full details regarding our schema at present, but, I can tell you, regarding the table where this is happening: the primary key is a single column being an unsigned integer, and the value that it’s set to is always provided externally, not auto-generated by the DB.

There are two columns that are DateTime columns. One is entirely optional, the other is required, and defaults to ‘now()’ via the schema having @default(now()).

The emailAddress column is required to be unique.

The error occurs with code that looks rather like this:

const user = await prisma.user.upsert({
  where: {
    emailAddress: '***@***.***',
  },
  update: {},
  create: {
    id: await generateUserID(),
    emailAddress: '***@***.***',
    firstGivenName: 'Fred',
    familyName: 'Flintstone',
    cellNumber: '+1800RUBBLE',
  },
});

The intent being to either retrieve (with no changes) the existing record (being retrieved by the unique column, not the primary ID column), or, create a new record (hence, the ‘update’ has an empty object). Either way, an object is supposed to be returned.

I believe, in most cases, the db record will already have been created, so it should be heading down the ‘update’ path.

I kinda wonder if, due to the DateTime issue (ie: data mangling causing exact matches to fail to find results), this is somehow also playing a part here, but, it could be something else entirely.

How to reproduce

const user = await prisma.user.upsert({
  where: {
    emailAddress: '***@***.***',
  },
  update: {},
  create: {
    id: await generateUserID(),
    emailAddress: '***@***.***',
    firstGivenName: 'Fred',
    familyName: 'Flintstone',
    cellNumber: '+1800RUBBLE',
  },
});

Expected behavior

The expected behavior is that either the existing record is returned, or, the newly created record is returned.

Prisma information

model User {
  id                            Int       @id @map("user_id")
  emailAddress        String    @unique @map("email_address")
  password               String
  firstGivenName     String    @map("first_given_name")
  familyName           String    @map("family_name")
  cellNumber            String?   @map("cell_number")
  created                   DateTime  @default(now())
  lastLogin                 DateTime? @map("last_login")

Environment & setup

  • OS: macOS
  • Database: MySQL
  • Node.js version: 16.16.0

Prisma Version

4.3.0

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:15 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
janpiocommented, Sep 28, 2022

Hey @Haschikeks, thanks for including a reproduction. This issue here was technically only about this error message when you try to write an overflowing unsigned int - the title just does not reflect that.

Can you please open a new bug report issue, include your current comment text from here and also the additional information it is asking for? Thanks! We will take a look as soon as possible then.

1reaction
Simonpedrocommented, Sep 26, 2022

@janpio I spent some time digging into it.

Do you have parallel requests that could delete the data while it is being modified by the upsert?

Yes, it’s likely that under certain conditions, we trigger an upsert followed by a delete. Nonetheless, I tried to replicate that case in different ways but failed in reproducing.

Regarding Peter’s findings, I couldn’t reproduce it either and don’t think it’s related, mainly because my @id column is of type String and I’m using Postgress.

I’ll keep an eye on it. I just improved the catch branch of the screenshot I had shared by adding more debugging information. If I find any insights, I’ll let you know via a new issue.

Thanks a lot!

Read more comments on GitHub >

github_iconTop Results From Across the Web

2 Server Error Message Reference - MySQL :: Developer Zone
Occurs for failure to create or copy a file needed for some operation. Possible causes: Permissions problem for source file; destination file already...
Read more >
BIGINT UNSIGNED VALUE IS out of range My SQL
Please read "Out-of-Range and Overflow Handling". It says: As of MySQL 5.5.5, overflow during numeric expression evaluation results in an error.
Read more >
MySQL bugs fixed by Aurora MySQL database engine updates
Fixed an issue where a stored procedure containing an IF statement using EXISTS, which acted on one or more tables that were deleted...
Read more >
MariaDB Error Codes
MariaDB shares error codes with MySQL, as well as adding a number of new error codes specific to MariaDB. An example of an...
Read more >
How to update 10 million+ rows in MySQL single table as Fast ...
I tried inserting data to a MyISAM table row by row and it took 35 minutes. I need to take only 3 values...
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