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

Error received when connecting items in an existing one-to-many relationship on MySQL #17103

Closed
borisno2 opened this issue Jan 2, 2023 · 4 comments · Fixed by prisma/prisma-engines#3679
Assignees
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/regression A reported bug in functionality that used to work before. team/client Issue for team Client. topic: connect topic: m:n many-to-many relations topic: mysql
Milestone

Comments

@borisno2
Copy link

borisno2 commented Jan 2, 2023

Bug description

Receiving the following error when using MySql and connecting two items in a one-to-many relationship that are already connected

prisma:query BEGIN
prisma:query INSERT INTO `testingPrisma48`.`B` (`id`) VALUES (?)
prisma:query INSERT INTO `testingPrisma48`.`A` (`id`,`bId`) VALUES (?,?)
prisma:query SELECT `testingPrisma48`.`A`.`id`, `testingPrisma48`.`A`.`bId` FROM `testingPrisma48`.`A` WHERE `testingPrisma48`.`A`.`id` = ? LIMIT ? OFFSET ?
prisma:query COMMIT
prisma:query BEGIN
prisma:query SELECT `testingPrisma48`.`B`.`id` FROM `testingPrisma48`.`B` WHERE (`testingPrisma48`.`B`.`id` = ? AND 1=1)
prisma:query UPDATE `testingPrisma48`.`A` SET `bId` = ? WHERE (`testingPrisma48`.`A`.`id` = ? AND 1=1)
prisma:query ROLLBACK
/Users/josh/Development/PrismaTesting48/node_modules/@prisma/client/runtime/index.js:35024
      throw new PrismaClientKnownRequestError(message, {
            ^
PrismaClientKnownRequestError: 
Invalid `client.b.update()` invocation in
/Users/josh/Development/PrismaTesting48/index.ts:7:17

  4 
  5 ;(async () => {
  6     const item = await client.a.create({ data: { b: { create: {} } } })
→ 7     await client.b.update(
The required connected records were not found. Expected 1 records to be connected after connect operation on one-to-many relation 'AToB', found 0.
    at RequestHandler.handleRequestError (/Users/josh/Development/PrismaTesting48/node_modules/@prisma/client/runtime/index.js:35024:13)
    at RequestHandler.handleAndLogRequestError (/Users/josh/Development/PrismaTesting48/node_modules/@prisma/client/runtime/index.js:34996:12)
    at RequestHandler.request (/Users/josh/Development/PrismaTesting48/node_modules/@prisma/client/runtime/index.js:34991:12)
    at async PrismaClient._request (/Users/josh/Development/PrismaTesting48/node_modules/@prisma/client/runtime/index.js:36082:16) {
  code: 'P2018',
  clientVersion: '4.8.0',
  meta: {
    details: "Expected 1 records to be connected after connect operation on one-to-many relation 'AToB', found 0."
  },
  batchRequestIdx: undefined
}

How to reproduce

  1. Create a project with the prisma.schema and index.ts below
  2. Install Prisma version 4.4.0 or above
  3. Run 'npx ts-node index.ts`
  4. See error above

Expected behavior

Expected relationship to stay the same and not error to be produced. Same behaviour as Postgres and SQLLite using Prisma 4.8.0 and MySQL using Prisma prior to 4.4.0
This is the result using Prisma version 4.3.1

prisma:query BEGIN
prisma:query INSERT INTO `testingPrisma48`.`B` (`id`) VALUES (?) /* traceparent=00-00-00-00 */
prisma:query INSERT INTO `testingPrisma48`.`A` (`id`,`bId`) VALUES (?,?) /* traceparent=00-00-00-00 */
prisma:query SELECT `testingPrisma48`.`A`.`id`, `testingPrisma48`.`A`.`bId` FROM `testingPrisma48`.`A` WHERE `testingPrisma48`.`A`.`id` = ? LIMIT ? OFFSET ? /* traceparent=00-00-00-00 */
prisma:query COMMIT
prisma:query BEGIN
prisma:query SELECT `testingPrisma48`.`B`.`id` FROM `testingPrisma48`.`B` WHERE `testingPrisma48`.`B`.`id` = ? /* traceparent=00-00-00-00 */
prisma:query SELECT `testingPrisma48`.`A`.`id` FROM `testingPrisma48`.`A` WHERE `testingPrisma48`.`A`.`id` = ? /* traceparent=00-00-00-00 */
prisma:query UPDATE `testingPrisma48`.`A` SET `bId` = ? WHERE `testingPrisma48`.`A`.`id` IN (?) /* traceparent=00-00-00-00 */
prisma:query SELECT `testingPrisma48`.`B`.`id` FROM `testingPrisma48`.`B` WHERE `testingPrisma48`.`B`.`id` = ? LIMIT ? OFFSET ? /* traceparent=00-00-00-00 */
prisma:query COMMIT

Prisma information

generator client {
  provider = "prisma-client-js"
}

datasource db {
  provider = "mysql"
  url      = env("DATABASE_URL")
}

model A {
  id  Int  @id @default(autoincrement())
  b   B?   @relation(fields: [bId], references: [id])
  bId Int?
}

model B {
  id Int @id @default(autoincrement())
  a  A[]
}
const { PrismaClient } = require('@prisma/client')

const client = new PrismaClient({ log: ['query'] })

;(async () => {
	const item = await client.a.create({ data: { b: { create: {} } } })
	await client.b.update({
		where: { id: item.bId },
		data: { a: { connect: [{ id: item.id }] } },
	})
})()

Environment & setup

  • OS:
  • Database:
  • Node.js version:

Prisma Version

prisma                  : 4.8.0
@prisma/client          : 4.8.0
Current platform        : darwin-arm64
Query Engine (Node-API) : libquery-engine d6e67a83f971b175a593ccc12e15c4a757f93ffe (at node_modules/@prisma/engines/libquery_engine-darwin-arm64.dylib.node)
Migration Engine        : migration-engine-cli d6e67a83f971b175a593ccc12e15c4a757f93ffe (at node_modules/@prisma/engines/migration-engine-darwin-arm64)
Introspection Engine    : introspection-core d6e67a83f971b175a593ccc12e15c4a757f93ffe (at node_modules/@prisma/engines/introspection-engine-darwin-arm64)
Format Binary           : prisma-fmt d6e67a83f971b175a593ccc12e15c4a757f93ffe (at node_modules/@prisma/engines/prisma-fmt-darwin-arm64)
Format Wasm             : @prisma/prisma-fmt-wasm 4.8.0-61.d6e67a83f971b175a593ccc12e15c4a757f93ffe
Default Engines Hash    : d6e67a83f971b175a593ccc12e15c4a757f93ffe
Studio                  : 0.479.0
@borisno2 borisno2 added the kind/bug A reported bug. label Jan 2, 2023
@jkomyno jkomyno added team/client Issue for team Client. bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. kind/regression A reported bug in functionality that used to work before. labels Jan 3, 2023
@janpio janpio added bug/2-confirmed Bug has been reproduced and confirmed. and removed kind/bug A reported bug. bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. labels Jan 3, 2023
@janpio
Copy link
Member

janpio commented Jan 3, 2023

Old:

PS C:\Users\Jan\Documents\throwaway\17103> npx ts-node index.ts
prisma:query BEGIN
prisma:query INSERT INTO `peach_newt`.`B` (`id`) VALUES (?) /* traceparent=00-00-00-00 */
prisma:query INSERT INTO `peach_newt`.`A` (`id`,`bId`) VALUES (?,?) /* traceparent=00-00-00-00 */
prisma:query SELECT `peach_newt`.`A`.`id`, `peach_newt`.`A`.`bId` FROM `peach_newt`.`A` WHERE `peach_newt`.`A`.`id` = ? LIMIT ? OFFSET ? /* traceparent=00-00-00-00 */
prisma:query COMMIT
prisma:query BEGIN
prisma:query SELECT `peach_newt`.`B`.`id` FROM `peach_newt`.`B` WHERE `peach_newt`.`B`.`id` = ? /* traceparent=00-00-00-00 */
prisma:query SELECT `peach_newt`.`A`.`id` FROM `peach_newt`.`A` WHERE `peach_newt`.`A`.`id` = ? /* traceparent=00-00-00-00 */
prisma:query UPDATE `peach_newt`.`A` SET `bId` = ? WHERE `peach_newt`.`A`.`id` IN (?) /* traceparent=00-00-00-00 */
prisma:query SELECT `peach_newt`.`B`.`id` FROM `peach_newt`.`B` WHERE `peach_newt`.`B`.`id` = ? LIMIT ? OFFSET ? /* traceparent=00-00-00-00 */
prisma:query COMMIT
PS C:\Users\Jan\Documents\throwaway\17103> npx prisma -v
Environment variables loaded from .env
prisma                  : 4.3.1
@prisma/client          : 4.3.1
Current platform        : windows
Query Engine (Node-API) : libquery-engine c875e43600dfe042452e0b868f7a48b817b9640b (at node_modules\@prisma\engines\query_engine-windows.dll.node)
Migration Engine        : migration-engine-cli c875e43600dfe042452e0b868f7a48b817b9640b (at node_modules\@prisma\engines\migration-engine-windows.exe)
Introspection Engine    : introspection-core c875e43600dfe042452e0b868f7a48b817b9640b (at node_modules\@prisma\engines\introspection-engine-windows.exe)
Format Binary           : prisma-fmt c875e43600dfe042452e0b868f7a48b817b9640b (at node_modules\@prisma\engines\prisma-fmt-windows.exe)
Format Wasm             : @prisma/prisma-fmt-wasm 4.3.0-32.c875e43600dfe042452e0b868f7a48b817b9640b
Default Engines Hash    : c875e43600dfe042452e0b868f7a48b817b9640b
Studio                  : 0.473.0

Newer:

PS C:\Users\Jan\Documents\throwaway\17103> npx prisma -v
Environment variables loaded from .env
prisma                  : 4.4.0
@prisma/client          : 4.4.0
Current platform        : windows
Query Engine (Node-API) : libquery-engine f352a33b70356f46311da8b00d83386dd9f145d6 (at node_modules\@prisma\engines\query_engine-windows.dll.node)
Migration Engine        : migration-engine-cli f352a33b70356f46311da8b00d83386dd9f145d6 (at node_modules\@prisma\engines\migration-engine-windows.exe)
Introspection Engine    : introspection-core f352a33b70356f46311da8b00d83386dd9f145d6 (at node_modules\@prisma\engines\introspection-engine-windows.exe)
Format Binary           : prisma-fmt f352a33b70356f46311da8b00d83386dd9f145d6 (at node_modules\@prisma\engines\prisma-fmt-windows.exe)
Format Wasm             : @prisma/prisma-fmt-wasm 4.4.0-66.f352a33b70356f46311da8b00d83386dd9f145d6
Default Engines Hash    : f352a33b70356f46311da8b00d83386dd9f145d6
Studio                  : 0.474.0
PS C:\Users\Jan\Documents\throwaway\17103> npx ts-node index.ts
prisma:query BEGIN
prisma:query INSERT INTO `peach_newt`.`B` (`id`) VALUES (?)
prisma:query INSERT INTO `peach_newt`.`A` (`id`,`bId`) VALUES (?,?)
prisma:query SELECT `peach_newt`.`A`.`id`, `peach_newt`.`A`.`bId` FROM `peach_newt`.`A` WHERE `peach_newt`.`A`.`id` = ? LIMIT ? OFFSET ?
prisma:query COMMIT
prisma:query BEGIN
prisma:query SELECT `peach_newt`.`B`.`id` FROM `peach_newt`.`B` WHERE `peach_newt`.`B`.`id` = ?
prisma:query UPDATE `peach_newt`.`A` SET `bId` = ? WHERE `peach_newt`.`A`.`id` = ?
prisma:query ROLLBACK
C:\Users\Jan\Documents\throwaway\17103\node_modules\@prisma\client\runtime\index.js:30851
      throw new PrismaClientKnownRequestError(message, error2.code, this.client._clientVersion, error2.meta);
            ^
PrismaClientKnownRequestError: 
Invalid `client.b.update()` invocation in
C:\Users\Jan\Documents\throwaway\17103\index.ts:7:17

  4 
  5 ;(async () => {
  6     const item = await client.a.create({ data: { b: { create: {} } } })
→ 7     await client.b.update(
The required connected records were not found. Expected 1 records to be connected after connect operation on one-to-many relation 'AToB', found 0.
    at RequestHandler.handleRequestError (C:\Users\Jan\Documents\throwaway\17103\node_modules\@prisma\client\runtime\index.js:30851:13)
    at RequestHandler.request (C:\Users\Jan\Documents\throwaway\17103\node_modules\@prisma\client\runtime\index.js:30834:12)
    at async PrismaClient._request (C:\Users\Jan\Documents\throwaway\17103\node_modules\@prisma\client\runtime\index.js:31812:16)
    at async C:\Users\Jan\Documents\throwaway\17103\index.ts:7:2 {
  code: 'P2018',
  clientVersion: '4.4.0',
  meta: {
    details: "Expected 1 records to be connected after connect operation on one-to-many relation 'AToB', found 0."
  }
}
PS C:\Users\Jan\Documents\throwaway\17103>

Newest:

PS C:\Users\Jan\Documents\throwaway\17103> npx prisma -v
Environment variables loaded from .env
prisma                  : 4.8.0
@prisma/client          : 4.8.0
Current platform        : windows
Query Engine (Node-API) : libquery-engine d6e67a83f971b175a593ccc12e15c4a757f93ffe (at node_modules\@prisma\engines\query_engine-windows.dll.node)
Migration Engine        : migration-engine-cli d6e67a83f971b175a593ccc12e15c4a757f93ffe (at node_modules\@prisma\engines\migration-engine-windows.exe)
Introspection Engine    : introspection-core d6e67a83f971b175a593ccc12e15c4a757f93ffe (at node_modules\@prisma\engines\introspection-engine-windows.exe)
Format Binary           : prisma-fmt d6e67a83f971b175a593ccc12e15c4a757f93ffe (at node_modules\@prisma\engines\prisma-fmt-windows.exe)
Format Wasm             : @prisma/prisma-fmt-wasm 4.8.0-61.d6e67a83f971b175a593ccc12e15c4a757f93ffe
Default Engines Hash    : d6e67a83f971b175a593ccc12e15c4a757f93ffe
Studio                  : 0.479.0
PS C:\Users\Jan\Documents\throwaway\17103> npx prisma generate
Environment variables loaded from .env
Prisma schema loaded from prisma\schema.prisma

✔ Generated Prisma Client (4.8.0 | library) to .\node_modules\@prisma\client in 83ms
You can now start using Prisma Client in your code. Reference: https://pris.ly/d/client
```
import { PrismaClient } from '@prisma/client'
const prisma = new PrismaClient()
```
PS C:\Users\Jan\Documents\throwaway\17103> npx ts-node index.ts
prisma:query BEGIN
prisma:query INSERT INTO `peach_newt`.`B` (`id`) VALUES (?)
prisma:query INSERT INTO `peach_newt`.`A` (`id`,`bId`) VALUES (?,?)
prisma:query SELECT `peach_newt`.`A`.`id`, `peach_newt`.`A`.`bId` FROM `peach_newt`.`A` WHERE `peach_newt`.`A`.`id` = ? LIMIT ? OFFSET ?
prisma:query COMMIT
prisma:query BEGIN
prisma:query SELECT `peach_newt`.`B`.`id` FROM `peach_newt`.`B` WHERE (`peach_newt`.`B`.`id` = ? AND 1=1)
prisma:query UPDATE `peach_newt`.`A` SET `bId` = ? WHERE (`peach_newt`.`A`.`id` = ? AND 1=1)
prisma:query ROLLBACK
C:\Users\Jan\Documents\throwaway\17103\node_modules\@prisma\client\runtime\index.js:35024
      throw new PrismaClientKnownRequestError(message, {
            ^
PrismaClientKnownRequestError: 
Invalid `client.b.update()` invocation in
C:\Users\Jan\Documents\throwaway\17103\index.ts:7:17

  4
  5 ;(async () => {
  6     const item = await client.a.create({ data: { b: { create: {} } } })
→ 7     await client.b.update(
The required connected records were not found. Expected 1 records to be connected after connect operation on one-to-many relation 'AToB', found 0.
    at RequestHandler.handleRequestError (C:\Users\Jan\Documents\throwaway\17103\node_modules\@prisma\client\runtime\index.js:35024:13)
    at RequestHandler.handleAndLogRequestError (C:\Users\Jan\Documents\throwaway\17103\node_modules\@prisma\client\runtime\index.js:34996:12)
    at RequestHandler.request (C:\Users\Jan\Documents\throwaway\17103\node_modules\@prisma\client\runtime\index.js:34991:12)
    at async PrismaClient._request (C:\Users\Jan\Documents\throwaway\17103\node_modules\@prisma\client\runtime\index.js:36082:16)
    at async C:\Users\Jan\Documents\throwaway\17103\index.ts:7:2 {
  code: 'P2018',
  clientVersion: '4.8.0',
  meta: {
    details: "Expected 1 records to be connected after connect operation on one-to-many relation 'AToB', found 0."
  },
  batchRequestIdx: undefined
}

@janpio janpio added the topic: m:n many-to-many relations label Jan 3, 2023
@Jolg42
Copy link
Member

Jolg42 commented Jan 4, 2023

I could pin down that to our internal version 4.4.0-dev.47 - 2022-09-20T11:08:56.018Z
https://buildkite.com/prisma/release-prisma-typescript/builds/7280#01835a7f-bc9d-4c20-b9d1-9c943c4ec4a4
PR: #15409
Which is a lot of different things

[2022-09-20T11:10:34Z] �[4m./prisma-engines�[24m �[1mgit tag -a 4.4.0-dev.47 f71b10418f535996bac94b190aa874900a0f7074 -m "4.4.0-dev.47" -m "f71b10418f535996bac94b190aa874900a0f7074" -m " * f71b10418f - Merge pull request #3203 from prisma/integration/qe/repair-overwrite-datasource - by Tom Houlé�[22m
[2022-09-20T11:10:34Z] �[1m * 8ac7ec83ea - qe: repair OVERWRITE_DATASOURCES param in binary CLI - by Tom Houlé�[22m
[2022-09-20T11:10:34Z] �[1m * fb56bfedb3 - Merge pull request #3198 from prisma/fix/migrate-prevent-deleting-postgis-columns - by Alberto Schiabel�[22m
[2022-09-20T11:10:34Z] �[1m * 32bdca578e - Fix formatting issue - by Alberto Schiabel�[22m
[2022-09-20T11:10:34Z] �[1m * 9a6bc87f2e - Add link as a comment - by Alberto Schiabel�[22m
[2022-09-20T11:10:34Z] �[1m * 2f2d44f817 - fix: prevent deletion of 'raster_columns' and 'raster_overviews' PostGIS columns in prisma migrate - by Alberto Schiabel�[22m
[2022-09-20T11:10:34Z] �[1m * 4124c5c9bd - Merge pull request #3196 from prisma/me/better-error-on-sqlite-truncation - by Tom Houlé�[22m
[2022-09-20T11:10:34Z] �[1m * 51e9120ed9 - me: close prisma/prisma#13991 - by Tom Houlé�[22m
[2022-09-20T11:10:34Z] �[1m * cf674bd0ec - fix(qe) OCC fixes for update/delete many - by Garren�[22m
[2022-09-20T11:10:34Z] �[1m * b40cafb6cf - only add trace comment to sql if we are tracing (#3188) - by Garren�[22m
[2022-09-20T11:10:34Z] �[1m * 06b6b4b107 - Merge pull request #3192 from prisma/prisma-engines-derivation-in-flake - by Tom Houlé�[22m
[2022-09-20T11:10:34Z] �[1m * 0827b8d9a9 - fix format issues on ci - by garren smith�[22m
[2022-09-20T11:10:34Z] �[1m * 13aa8a6220 - cargo fmt - by Tom Houlé�[22m
[2022-09-20T11:10:34Z] �[1m * 248b80264d - nix: add a derivation for all binaries in flake - by Tom Houlé�[22m
[2022-09-20T11:10:34Z] �[1m * 7135d84a57 - Merge pull request #3185 from prisma/qe/prisma-14001 - by Tom Houlé�[22m
[2022-09-20T11:10:34Z] �[1m * dc7a16204a - Merge pull request #3186 from prisma/qe/prisma-13097 - by Tom Houlé�[22m
[2022-09-20T11:10:34Z] �[1m * 2404d47630 - Use mainline cuid instead of our fork (#3189) - by Julius de Bruijn�[22m
[2022-09-20T11:10:34Z] �[1m * ae9a5a5bab - qe: fix prisma/13097 - by Tom Houlé�[22m
[2022-09-20T11:10:34Z] �[1m * 80833cfa57 - Merge pull request #3187 from prisma/psl/dml-free-core - by Tom Houlé�[22m
[2022-09-20T11:10:34Z] �[1m * cf80d03453 - psl: decouple datasource loader from builtin connectors - by Tom Houlé�[22m
[2022-09-20T11:10:34Z] �[1m * 0769354ed4 - psl: invert the dependency between dml and core - by Tom Houlé�[22m
[2022-09-20T11:10:34Z] �[1m * 23b40ab9a7 - qe: fix prisma/14001 - by Tom Houlé�[22m
[2022-09-20T11:10:34Z] �[1m * a652eea41b - Merge pull request #3182 from prisma/qe/internal-dm-builder-2 - by Tom Houlé�[22m
[2022-09-20T11:10:34Z] �[1m * 77188e3286 - query-engine-node-api: replace unnecessary dml usage - by Tom Houlé�[22m
[2022-09-20T11:10:34Z] �[1m * 9e363b4b8a - qe: replace InternalDatamodelBuilder with a simple fn - by Tom Houlé�[22m
[2022-09-20T11:10:34Z] �[1m * f30de5323a - Merge pull request #3181 from prisma/qe/internal-dm-builder - by Tom Houlé�[22m
[2022-09-20T11:10:34Z] �[1m * 3f0ae6c8a2 - psl: simplify parse_configuration - by Tom Houlé�[22m
[2022-09-20T11:10:34Z] �[1m * 7856f0aca6 - psl: shrink the public api even further - by Tom Houlé�[22m
[2022-09-20T11:10:34Z] �[1m * 32c9c38244 - Merge pull request #3180 from prisma/psl/shrink-public-api - by Tom Houlé�[22m
[2022-09-20T11:10:34Z] �[1m * 3efffdaf51 - Merge pull request #3179 from prisma/qe/dmmf-fixes - by Tom Houlé�[22m
[2022-09-20T11:10:34Z] �[1m * 2279fc4b61 - psl: drop parse_schema_ast - by Tom Houlé�[22m
[2022-09-20T11:10:34Z] �[1m * d51f38caf6 - psl: shrink public API - by Tom Houlé�[22m
[2022-09-20T11:10:34Z] �[1m * 19590b5fec - qe: correct dmmf changes inadvertently introduced in 7e0dbcd28cc971c33e3b0852ecce79d20b35661f - by Tom Houlé�[22m
[2022-09-20T11:10:34Z] �[1m * 5ea52dba31 - Merge pull request #3178 from prisma/qe/uuid-filters - by Tom Houlé�[22m
[2022-09-20T11:10:34Z] �[1m * 7e0dbcd28c - qe+postgres: exclude \`contains\` filters on uuid fields - by Tom Houlé"�[22m
➜  17103 yarn && yarn prisma generate && ts-node main
yarn install v1.22.19
[1/4] 🔍  Resolving packages...
success Already up-to-date.
✨  Done in 0.03s.
yarn run v1.22.19
$ /Users/j42/Repros/17103/node_modules/.bin/prisma generate
Environment variables loaded from prisma/.env
Prisma schema loaded from prisma/schema.prisma

✔ Generated Prisma Client (4.4.0-dev.47 | library) to ./node_modules/@prisma/client in 30ms
You can now start using Prisma Client in your code. Reference: https://pris.ly/d/client
...
✨  Done in 0.79s.
prisma:query BEGIN
prisma:query INSERT INTO `17103`.`B` (`id`) VALUES (?)
prisma:query INSERT INTO `17103`.`A` (`id`,`bId`) VALUES (?,?)
prisma:query SELECT `17103`.`A`.`id`, `17103`.`A`.`bId` FROM `17103`.`A` WHERE `17103`.`A`.`id` = ? LIMIT ? OFFSET ?
prisma:query COMMIT
{ id: 10, bId: 10 }
prisma:query BEGIN
prisma:query SELECT `17103`.`B`.`id` FROM `17103`.`B` WHERE `17103`.`B`.`id` = ?
prisma:query SELECT `17103`.`A`.`id` FROM `17103`.`A` WHERE `17103`.`A`.`id` = ?
prisma:query UPDATE `17103`.`A` SET `bId` = ? WHERE (`17103`.`A`.`id` IN (?) AND `17103`.`A`.`id` = ?)
prisma:query ROLLBACK
/Users/j42/Repros/17103/node_modules/@prisma/client/runtime/index.js:30838
      throw new PrismaClientKnownRequestError(message, error2.code, this.client._clientVersion, error2.meta);
            ^
PrismaClientKnownRequestError: 
Invalid `prisma.b.update()` invocation in
/Users/j42/Repros/17103/main.ts:9:18

  6 const item = await prisma.a.create({ data: { b: { create: {} } } });
  7 console.log(item);
  8 
→ 9 await prisma.b.update(
The required connected records were not found. Expected 1 records to be connected after connect operation on one-to-many relation 'AToB', found 0.
    at RequestHandler.handleRequestError (/Users/j42/Repros/17103/node_modules/@prisma/client/runtime/index.js:30838:13)
    at RequestHandler.request (/Users/j42/Repros/17103/node_modules/@prisma/client/runtime/index.js:30821:12)
    at async PrismaClient._request (/Users/j42/Repros/17103/node_modules/@prisma/client/runtime/index.js:31792:16)
    at async main (/Users/j42/Repros/17103/main.ts:9:3) {
  code: 'P2018',
  clientVersion: '4.4.0-dev.47',
  meta: {
    details: "Expected 1 records to be connected after connect operation on one-to-many relation 'AToB', found 0."
  }
}
➜  17103 yarn && yarn prisma generate && ts-node main
yarn install v1.22.19
[1/4] 🔍  Resolving packages...
[2/4] 🚚  Fetching packages...
[3/4] 🔗  Linking dependencies...
[4/4] 🔨  Building fresh packages...
success Saved lockfile.
✨  Done in 4.34s.
yarn run v1.22.19
$ /Users/j42/Repros/17103/node_modules/.bin/prisma generate
Environment variables loaded from prisma/.env
Prisma schema loaded from prisma/schema.prisma

✔ Generated Prisma Client (4.4.0-dev.46 | library) to ./node_modules/@prisma/client in 232ms
You can now start using Prisma Client in your code. Reference: https://pris.ly/d/client
...
✨  Done in 1.26s.
prisma:query BEGIN
prisma:query INSERT INTO `17103`.`B` (`id`) VALUES (?) /* traceparent=00-00-00-00 */
prisma:query INSERT INTO `17103`.`A` (`id`,`bId`) VALUES (?,?) /* traceparent=00-00-00-00 */
prisma:query SELECT `17103`.`A`.`id`, `17103`.`A`.`bId` FROM `17103`.`A` WHERE `17103`.`A`.`id` = ? LIMIT ? OFFSET ? /* traceparent=00-00-00-00 */
prisma:query COMMIT
{ id: 11, bId: 11 }
prisma:query BEGIN
prisma:query SELECT `17103`.`B`.`id` FROM `17103`.`B` WHERE `17103`.`B`.`id` = ? /* traceparent=00-00-00-00 */
prisma:query SELECT `17103`.`A`.`id` FROM `17103`.`A` WHERE `17103`.`A`.`id` = ? /* traceparent=00-00-00-00 */
prisma:query UPDATE `17103`.`A` SET `bId` = ? WHERE `17103`.`A`.`id` IN (?) /* traceparent=00-00-00-00 */
prisma:query SELECT `17103`.`B`.`id` FROM `17103`.`B` WHERE `17103`.`B`.`id` = ? LIMIT ? OFFSET ? /* traceparent=00-00-00-00 */
prisma:query COMMIT

@Jolg42
Copy link
Member

Jolg42 commented Jan 4, 2023

This would be the diff in prisma-engines prisma/prisma-engines@4.4.0-dev.46...4.4.0-dev.47

@Weakky
Copy link
Member

Weakky commented Feb 8, 2023

Hey folks, we've just fixed this issue. Thanks for the useful and concise reproduction, it will be available in Prisma 4.11.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/regression A reported bug in functionality that used to work before. team/client Issue for team Client. topic: connect topic: m:n many-to-many relations topic: mysql
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants