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

wrong error message/header on multiple table upsert using transaction #15433

Closed
hitzam-wartek opened this issue Sep 21, 2022 · 2 comments · Fixed by #16240
Closed

wrong error message/header on multiple table upsert using transaction #15433

hitzam-wartek opened this issue Sep 21, 2022 · 2 comments · Fixed by #16240
Assignees
Labels
bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. kind/bug A reported bug. team/client Issue for team Client. topic: transaction topic: upsert nested upsert
Milestone

Comments

@hitzam-wartek
Copy link

Bug description

Hi Prisma team,
So, I have 3 tables that need to upsert at once using transaction, and I need to log the exception when something wrong on execution.

I tried to make the execution failed by putting some invalid data of first table. and it worked well, I got the error message & the error detail correctly, something like Error: Invalid prisma.table_1.upsert() invocation: --detail error message that related to table 1--.

on second attempt, I put invalid data on the second table, and it's not worked as expected, the error message/header still referring to first table while the error detail relates to second table. Error: Invalid prisma.table_1.upsert() invocation: --detail error message that related to table 2--.

it also happen when something is wrong on the 3rd table, the error header still refering to 1st table.

How to reproduce

Expected behavior

expected behavior: error message/header should refer to the table where the error comes.

Error: Invalid prisma.table_1.upsert() invocation: --detail error message that related to table 1--.
Error: Invalid prisma.table_2.upsert() invocation: --detail error message that related to table 2--.
Error: Invalid prisma.table_3.upsert() invocation: --detail error message that related to table 3--.

Prisma information

// Add your schema.prisma
// Add your code using Prisma Client

Environment & setup

  • OS: windows, ubuntu
  • Database: SQL Server
  • Node.js version: v16.13.2

Prisma Version

"prisma": "^4.0.0"
@hitzam-wartek hitzam-wartek added the kind/bug A reported bug. label Sep 21, 2022
@garrensmith
Copy link
Contributor

@hitzam-wartek could you share your schema and the query you are doing? A reproduction would also help us here.

@hitzam-wartek
Copy link
Author

hitzam-wartek commented Sep 21, 2022

Hi @garrensmith, here's the schema & query

model sekolah_penjab {
  id_penjab       String      @id(map: "PK_sekolah_penjab", clustered: false) @db.UniqueIdentifier
  sekolah_id      String      @db.UniqueIdentifier
  tanggal_mulai   DateTime    @db.Date
  tanggal_selesai DateTime    @db.Date
  ks              String?     @db.NVarChar(80)
  nip_ks          String?     @db.NVarChar(20)
  email_ks        String?     @db.NVarChar(100)
  telp_ks         String?     @db.NVarChar(20)
  bendahara       String?     @db.NVarChar(50)
  nip_bendahara   String?     @db.NVarChar(20)
  email_bendahara String?     @db.NVarChar(100)
  telp_bendahara  String?     @db.NVarChar(20)
  komite          String?     @db.NVarChar(50)
  nip_komite      String?     @db.NVarChar(100)
  soft_delete     Decimal?    @db.Decimal(1, 0)
  create_date     DateTime
  last_update     DateTime
  updater_id      String?     @db.UniqueIdentifier
  mst_sekolah     mst_sekolah @relation(fields: [sekolah_id], references: [sekolah_id], onUpdate: NoAction, map: "FK_sekolah_penjab_mst_sekolah_sekolah_id")

  @@index([sekolah_id], map: "IX_sekolah_penjab_sekolah_id")
}

model anggaran {
  id_anggaran            String                   @id(map: "PK_anggaran") @db.UniqueIdentifier
  id_ref_sumber_dana     Decimal                  @db.Decimal(2, 0)
  sekolah_id             String                   @db.UniqueIdentifier
  volume                 Decimal?                 @db.Decimal(6, 0)
  harga_satuan           Float?                   @db.Money
  jumlah                 Float?                   @db.Money
  sisa_anggaran          Float?                   @db.Money
  is_pengesahan          Decimal?                 @default(0, map: "DF__anggaran__is_pen__09746778") @db.Decimal(1, 0)
  tanggal_pengajuan      DateTime?
  tanggal_pengesahan     DateTime?
  is_approve             Decimal                  @db.Decimal(1, 0)
  is_revisi              Decimal?                 @default(0, map: "DF__anggaran__is_rev__0880433F") @db.Decimal(3, 0)
  alasan_penolakan       String?                  @db.NVarChar(4000)
  is_aktif               Decimal                  @db.Decimal(1, 0)
  soft_delete            Decimal                  @db.Decimal(1, 0)
  create_date            DateTime
  last_update            DateTime
  updater_id             String?                  @db.UniqueIdentifier
  id_penjab              String?                  @db.UniqueIdentifier
  ref_sumber_dana        ref_sumber_dana          @relation(fields: [id_ref_sumber_dana], references: [id_ref_sumber_dana], onUpdate: NoAction, map: "FK_anggaran_ref_sumber_dana_id_ref_sumber_dana")
  mst_sekolah            mst_sekolah              @relation(fields: [sekolah_id], references: [sekolah_id], onUpdate: NoAction, map: "FK_anggaran_mst_sekolah_sekolah_id")
  aktivasi_bku           aktivasi_bku[]
  kas_umum               kas_umum[]
  pengesahan             pengesahan[]
  rapbs                  rapbs[]
  rencana_kerja_anggaran rencana_kerja_anggaran[]

  @@index([id_ref_sumber_dana], map: "IX_anggaran_id_ref_sumber_dana")
  @@index([sekolah_id, is_revisi, soft_delete], map: "IX_anggaran_sekolah_id_is_revisi_soft_delete")
}

model rapbs {
  id_rapbs              String            @id(map: "PK_rapbs") @db.UniqueIdentifier
  sekolah_id            String            @db.UniqueIdentifier
  id_anggaran           String            @db.UniqueIdentifier
  id_ref_kode           String            @db.UniqueIdentifier
  id_ref_tahun_anggaran Decimal           @db.Decimal(4, 0)
  kode_rekening         String            @db.NVarChar(20)
  id_barang             String?           @db.NVarChar(40)
  urutan                String?           @db.NVarChar(3)
  uraian                String            @db.NVarChar(500)
  uraian_text           String?           @db.NVarChar(500)
  volume                Decimal           @db.Decimal(10, 0)
  satuan                String            @db.NVarChar(30)
  harga_satuan          Float             @db.Money
  jumlah                Float             @db.Money
  v1                    Decimal?          @db.Decimal(10, 0)
  s1                    String?           @db.NVarChar(30)
  v2                    Decimal?          @db.Decimal(10, 0)
  s2                    String?           @db.NVarChar(30)
  v3                    Decimal?          @db.Decimal(10, 0)
  s3                    String?           @db.NVarChar(30)
  v4                    Decimal?          @db.Decimal(10, 0)
  s4                    String?           @db.NVarChar(30)
  keterangan            String?           @db.NVarChar(2000)
  soft_delete           Decimal           @db.Decimal(1, 0)
  create_date           DateTime
  last_update           DateTime
  updater_id            String?           @db.UniqueIdentifier
  anggaran              anggaran          @relation(fields: [id_anggaran], references: [id_anggaran], onUpdate: NoAction, map: "FK_rapbs_anggaran_id_anggaran")
  ref_acuan_barang      ref_acuan_barang? @relation(fields: [id_barang], references: [id_barang], onDelete: NoAction, onUpdate: NoAction, map: "FK_rapbs_ref_acuan_barang_id_barang")
  ref_kode              ref_kode          @relation(fields: [id_ref_kode], references: [id_ref_kode], onUpdate: NoAction, map: "FK_rapbs_ref_kode_id_ref_kode")
  ref_rekening          ref_rekening      @relation(fields: [kode_rekening], references: [kode_rekening], onUpdate: NoAction, map: "FK_rapbs_ref_rekening_kode_rekening")
  mst_sekolah           mst_sekolah       @relation(fields: [sekolah_id], references: [sekolah_id], onUpdate: NoAction, map: "FK_rapbs_mst_sekolah_sekolah_id")
  pengesahan            pengesahan[]
  rapbs_periode         rapbs_periode[]

  @@index([id_barang], map: "IX_rapbs_id_barang")
  @@index([id_ref_kode], map: "IX_rapbs_id_ref_kode")
  @@index([sekolah_id], map: "IX_rapbs_sekolah_id")
  @@index([id_anggaran, soft_delete], map: "IX_rapbs_id_anggaran_soft_delete")
  @@index([kode_rekening, soft_delete], map: "IX_rapbs_kode_rekening_soft_delete")
  @@index([soft_delete], map: "IX_rapbs_soft_delete")
}
penjabData.map((data) =>
            queries.push(
                dbContext.sekolah_penjab.upsert({
                    where: {
                        id_penjab: data.id_penjab,
                    },
                    create: data,
                    update: data,
                })
            )
        );
anggaranData.map((data) =>
        queries.push(
            dbContext.anggaran.upsert({
                where: {
                    id_anggaran: data.id_anggaran,
                },
                create: data,
                update: data,
            })
        )
    );
rkasData.map((data) =>
        queries.push(
            dbContext.rapbs.upsert({
                where: {
                    id_rapbs: data.id_rapbs,
                },
                create: data,
                update: data,
            })
        )
    );

try {
        const results = await dbContext.$transaction(queries);
        logger.info(`${results.length} rows affected.`);
    } catch (error) {
        logger.error(`failed to upsert data, error message: ${error}`);
}

@millsp millsp added team/client Issue for team Client. bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. bug/0-unknown Bug is new, does not have information for reproduction or reproduction could not be confirmed. and removed bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. labels Sep 21, 2022
@janpio janpio removed the bug/0-unknown Bug is new, does not have information for reproduction or reproduction could not be confirmed. label Sep 22, 2022
@millsp millsp self-assigned this Oct 19, 2022
SevInf added a commit to prisma/prisma-engines that referenced this issue Nov 11, 2022
Adds `batch_request_idx` property to user facing errors. On the client,
that would allow us to build correct error message for `$transaction`
errors.

Ref: prisma/prisma#15433, prisma/prisma#14373
SevInf added a commit to prisma/prisma-engines that referenced this issue Nov 11, 2022
Adds `batch_request_idx` property to user facing errors. On the client,
that would allow us to build correct error message for `$transaction`
errors.

Ref: prisma/prisma#15433, prisma/prisma#14373
SevInf added a commit that referenced this issue Nov 11, 2022
Engine PR: prisma/prisma-engines#3384

Uses newly added `batch_request_idx` property of an errors to identify
and correctly report error location within a batch.

Fix #15433
Fix #14373
SevInf added a commit to prisma/prisma-engines that referenced this issue Nov 11, 2022
Adds `batch_request_idx` property to user facing errors. On the client,
that would allow us to build correct error message for `$transaction`
errors.

Ref: prisma/prisma#15433, prisma/prisma#14373
SevInf added a commit that referenced this issue Nov 11, 2022
Engine PR: prisma/prisma-engines#3384

Uses newly added `batch_request_idx` property of an errors to identify
and correctly report error location within a batch.

Fix #15433
Fix #14373
SevInf added a commit that referenced this issue Nov 11, 2022
Engine PR: prisma/prisma-engines#3384

Uses newly added `batch_request_idx` property of an errors to identify
and correctly report error location within a batch.

Fix #15433
Fix #14373
SevInf added a commit that referenced this issue Nov 14, 2022
Engine PR: prisma/prisma-engines#3384

Uses newly added `batch_request_idx` property of an errors to identify
and correctly report error location within a batch.

Fix #15433
Fix #14373
SevInf added a commit to prisma/prisma-engines that referenced this issue Nov 15, 2022
* qe: Identify which request in a batch caused error

Adds `batch_request_idx` property to user facing errors. On the client,
that would allow us to build correct error message for `$transaction`
errors.

Ref: prisma/prisma#15433, prisma/prisma#14373
SevInf added a commit that referenced this issue Nov 15, 2022
Engine PR: prisma/prisma-engines#3384

Uses newly added `batch_request_idx` property of an errors to identify
and correctly report error location within a batch.

Fix #15433
Fix #14373
@SevInf SevInf assigned SevInf and unassigned millsp Nov 15, 2022
SevInf added a commit that referenced this issue Nov 15, 2022
Engine PR: prisma/prisma-engines#3384

Uses newly added `batch_request_idx` property of an errors to identify
and correctly report error location within a batch.

Fix #15433
Fix #14373
SevInf added a commit that referenced this issue Nov 16, 2022
Engine PR: prisma/prisma-engines#3384

Uses newly added `batch_request_idx` property of an errors to identify
and correctly report error location within a batch.

Fix #15433
Fix #14373
SevInf added a commit that referenced this issue Nov 16, 2022
Engine PR: prisma/prisma-engines#3384

Uses newly added `batch_request_idx` property of an errors to identify
and correctly report error location within a batch.

Fix #15433
Fix #14373
SevInf added a commit that referenced this issue Nov 17, 2022
Engine PR: prisma/prisma-engines#3384

Uses newly added `batch_request_idx` property of an errors to identify
and correctly report error location within a batch.

Fix #15433
Fix #14373
SevInf added a commit that referenced this issue Nov 17, 2022
…6240)

Engine PR: prisma/prisma-engines#3384

Uses newly added `batch_request_idx` property of an errors to identify
and correctly report error location within a batch.

Fix #15433
Fix #14373
@janpio janpio added this to the 4.7.0 milestone Nov 17, 2022
jkomyno pushed a commit that referenced this issue Dec 21, 2022
…6240)

Engine PR: prisma/prisma-engines#3384

Uses newly added `batch_request_idx` property of an errors to identify
and correctly report error location within a batch.

Fix #15433
Fix #14373
jkomyno pushed a commit that referenced this issue Dec 21, 2022
…6240)

Engine PR: prisma/prisma-engines#3384

Uses newly added `batch_request_idx` property of an errors to identify
and correctly report error location within a batch.

Fix #15433
Fix #14373
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. kind/bug A reported bug. team/client Issue for team Client. topic: transaction topic: upsert nested upsert
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants