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

PANIC in libs/prisma-models/src/record.rs:161:30Invalid coercion encountered: ConversionFailure("Json(\"{\\\"bytes\\\":\\\"00000064844ee372092b5e6dc4aede92f276efec344e\\\"}\")", "Json") #7891

Closed
ac10n opened this issue Jun 27, 2021 · 3 comments
Assignees
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. team/client Issue for team Client. topic: basic error report topic: Json Scalar type `Json`

Comments

@ac10n
Copy link

ac10n commented Jun 27, 2021

Hi Prisma Team! My Prisma Client just crashed. This is the report:

Versions

Name Version
Node v16.3.0
OS rhel-openssl-1.1.x
Prisma Client 2.25.0
Query Engine query-engine c838e79f39885bc8e1611849b1eb28b5bb5bc922
Database undefined

Query

query {
  findManybigmap(distinct: [key]) {
    key
  }
}

Logs

  prisma:tryLoadEnv Environment variables loaded from /home/alireza/somepath/prisma-distinct-bug/.env  
  prisma:tryLoadEnv Environment variables loaded from /home/alireza/somepath/prisma-distinct-bug/.env  
  prisma:client clientVersion: 2.25.0  
  prisma:engine { cwd: '/home/alireza/somepath/prisma-distinct-bug/prisma' }  
  prisma:engine Search for Query Engine in /home/alireza/somepath/prisma-distinct-bug/node_modules/.prisma/client  
  prisma:engine Search for Query Engine in /home/alireza/somepath/prisma-distinct-bug/node_modules/.prisma/client  
  plusX Execution permissions of /home/alireza/somepath/prisma-distinct-bug/node_modules/.prisma/client/query-engine-rhel-openssl-1.1.x are fine  
  plusX Execution permissions of /home/alireza/somepath/prisma-distinct-bug/node_modules/.prisma/client/query-engine-rhel-openssl-1.1.x are fine  
  prisma:engine { flags: [ '--enable-raw-queries', '--port', '36629' ] }  
  prisma:engine stdout  Starting a postgresql pool with 9 connections.  
  prisma:engine stdout  Started http server on http://127.0.0.1:36629  
  prisma:engine Search for Query Engine in /home/alireza/somepath/prisma-distinct-bug/node_modules/.prisma/client  
  plusX Execution permissions of /home/alireza/somepath/prisma-distinct-bug/node_modules/.prisma/client/query-engine-rhel-openssl-1.1.x are fine  
  prisma:engine Client Version: 2.25.0  
  prisma:engine Engine Version: query-engine c838e79f39885bc8e1611849b1eb28b5bb5bc922  
  prisma:engine Active provider: postgresql  
  prisma:engine stdout  PANIC in libs/prisma-models/src/record.rs:161:30
Invalid coercion encountered: ConversionFailure("Json(\"{\\\"bytes\\\":\\\"00000064844ee372092b5e6dc4aede92f276efec344e\\\"}\")", "Json")  
  prisma:engine {
  prisma:engine   error: SocketError: other side closed
  prisma:engine       at Socket.onSocketEnd (/home/alireza/somepath/prisma-distinct-bug/node_modules/@prisma/client/runtime/index.js:25736:24)
  prisma:engine       at Socket.emit (node:events:406:35)
  prisma:engine       at Socket.emit (node:domain:470:12)
  prisma:engine       at endReadableNT (node:internal/streams/readable:1329:12)
  prisma:engine       at processTicksAndRejections (node:internal/process/task_queues:83:21) {
  prisma:engine     code: 'UND_ERR_SOCKET'
  prisma:engine   }
  prisma:engine }  
  prisma:engine {
  prisma:engine   error: Error: connect ECONNREFUSED 127.0.0.1:36629
  prisma:engine       at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1133:16) {
  prisma:engine     errno: -111,
  prisma:engine     code: 'ECONNREFUSED',
  prisma:engine     syscall: 'connect',
  prisma:engine     address: '127.0.0.1',
  prisma:engine     port: 36629
  prisma:engine   }
  prisma:engine }  
  prisma:engine { cwd: '/home/alireza/somepath/prisma-distinct-bug/prisma' }  
  prisma:engine Search for Query Engine in /home/alireza/somepath/prisma-distinct-bug/node_modules/.prisma/client  
  plusX Execution permissions of /home/alireza/somepath/prisma-distinct-bug/node_modules/.prisma/client/query-engine-rhel-openssl-1.1.x are fine  
  prisma:engine { flags: [ '--enable-raw-queries', '--port', '45801' ] }  
  prisma:engine stdout  Starting a postgresql pool with 9 connections.  
  prisma:engine stdout  Started http server on http://127.0.0.1:45801  
  prisma:engine Search for Query Engine in /home/alireza/somepath/prisma-distinct-bug/node_modules/.prisma/client  
  plusX Execution permissions of /home/alireza/somepath/prisma-distinct-bug/node_modules/.prisma/client/query-engine-rhel-openssl-1.1.x are fine  
  prisma:engine stdout  PANIC in libs/prisma-models/src/record.rs:161:30
Invalid coercion encountered: ConversionFailure("Json(\"{\\\"bytes\\\":\\\"00000064844ee372092b5e6dc4aede92f276efec344e\\\"}\")", "Json")  
  prisma:engine {
  prisma:engine   error: SocketError: other side closed
  prisma:engine       at Socket.onSocketEnd (/home/alireza/somepath/prisma-distinct-bug/node_modules/@prisma/client/runtime/index.js:25736:24)
  prisma:engine       at Socket.emit (node:events:406:35)
  prisma:engine       at Socket.emit (node:domain:470:12)
  prisma:engine       at endReadableNT (node:internal/streams/readable:1329:12)
  prisma:engine       at processTicksAndRejections (node:internal/process/task_queues:83:21) {
  prisma:engine     code: 'UND_ERR_SOCKET'
  prisma:engine   }
  prisma:engine }  

Client Snippet

const b = await prisma.bigmap.findMany({
        select: {
            key: true
        },
        distinct: ['i']
    });

Schema

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

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

model bigmap {
  id            BigInt?
  key           Json?
  key_hash      String?  @db.Char(54)
  key_type      Json?
  value         Json?
  value_type    Json?
  block_hash_id Int
  block_level   Int
  operation_id  BigInt
  sender_id     BigInt
  receiver_id   BigInt
  name          String?
  i             BigInt
  kind          Int      @db.SmallInt
  annots        String?
  strings       String[]
  uri           Int[]
  contracts     BigInt[]

  @@id([block_hash_id, i])
}

##Data

-- public.bigmap definition

-- Drop table

-- DROP TABLE bigmap;

CREATE TABLE bigmap (
	id int8 NULL,
	"key" jsonb NULL,
	key_hash bpchar(54) NULL,
	"key_type" jsonb NULL,
	value jsonb NULL,
	value_type jsonb NULL,
	block_hash_id int4 NOT NULL,
	block_level int4 NOT NULL,
	operation_id int8 NOT NULL,
	sender_id int8 NOT NULL,
	receiver_id int8 NOT NULL,
	"name" text NULL,
	i int8 NOT NULL,
	kind int2 NOT NULL,
	annots text NULL,
	strings _text NULL,
	uri _int4 NULL,
	contracts _int8 NULL,
	CONSTRAINT bigmap_pkey PRIMARY KEY (block_hash_id, I)
);

INSERT INTO public.bigmap (id,"key",key_hash,"key_type",value,value_type,block_hash_id,block_level,operation_id,sender_id,receiver_id,"name",i,kind,annots,strings,uri,contracts) VALUES
	 (106,'{"bytes": "00000064844ee372092b5e6dc4aede92f276efec344e"}','exprtgENdRqdnbxLjnqfT1vXf2TwQVatnSWGEatYJw7GK3VH643iSS',NULL,'{"int": "1"}',NULL,1498085,1498085,14980850000052,385637,353996,NULL,43,1,NULL,NULL,NULL,NULL),
	 (106,'{"bytes": "00000064844ee372092b5e6dc4aede92f276efec344e"}','exprtgENdRqdnbxLjnqfT1vXf2TwQVatnSWGEatYJw7GK3VH643iSS',NULL,'{"int": "2"}',NULL,1527473,1527473,15274730000072,385637,353996,NULL,57,1,NULL,NULL,NULL,NULL);

Actually, only the key column is important.

@janpio janpio added the team/client Issue for team Client. label Jun 30, 2021
@pantharshit00
Copy link
Contributor

Thanks for the clear reproduction, I can confirm this bug.

We have similar conversion issues reported but this is the only one which talks about a JSON field so we will treat this as a separate bug.

@pantharshit00 pantharshit00 added bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. process/candidate labels Jul 8, 2021
@ac10n
Copy link
Author

ac10n commented Jul 8, 2021

Hello Harshit

I have more interesting (and confusing) information:

  1. To work around this problem, I created a database view that did the distinct on inside the view
  2. Interestingly, the problem persisted
  3. In my case, the column of interest (key) was part of a unique key. Removing it fixed the problem.
  4. In the reproduction code, column key is not part of a unique key.

So, my guess is: we have some problems with a json column be part of a unique key.
In the reproduction code, after doing disctinct, prisma (rightfully) considers this column a key and fails.
In my workaround, I had explicitly marked it as key, removing it fixed the problem.

Maybe this information can help in pinning down the bug.

@pantharshit00
Copy link
Contributor

Thanks for providing more information, this will definitely help!

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/bug A reported bug. team/client Issue for team Client. topic: basic error report topic: Json Scalar type `Json`
Projects
None yet
Development

No branches or pull requests

5 participants