prisma / prisma-test-utils

A collection of data model agnostic test utils.
113 stars 11 forks source link

PANIC: column on null constraint violation error #25

Open janpio opened 4 years ago

janpio commented 4 years ago

When using prisma-test-utils via prisma-test-utils-automation, some databases (schemas from: https://github.com/prisma/database-schema-examples) fail with this error message:

Error in: chinook (postgres)
PrismaClientUnknownRequestError:
Invalid `seed = await client[methodName].create()` invocation in
C:\Users\Jan\Documents\prisma-test-utils\src\static\seed.ts:973:45

   969
   970 /**
   971  * Load the data to database.
   972  */
→  973 const seed = await client[methodName].create(

PANIC: column on null constraint violation error
    at PrismaClientFetcher.request (C:\Users\Jan\Documents\prisma-test-utils-automation\dbs\chinook\node_modules\prisma-client\index.js:90:17)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
divyenduz commented 4 years ago

I don't know how you ran into this with Chinook. I could only observe this for the database mentioned below.

I am not fully sure what this is about yet, maybe inserting a record with the respective foreign key record not inserted yet.


Internal notes:

Test utils database(s) affected:

2020-03-11T13:57:51.935Z prisma-client prisma.providers_individuals.create({
  data: {
    credentials: 'zeenejom',
    gender: 'ju',
    name_first: 'bu',
    name_last: 'mahbu',
    name_middle: 'wot',
    npi: 2
  }
})
2020-03-11T13:57:51.935Z prisma-client Generated request:
2020-03-11T13:57:51.935Z prisma-client mutation {
  createOneproviders_individuals(data: {
    credentials: "zeenejom"
    gender: "ju"
    name_first: "bu"
    name_last: "mahbu"
    name_middle: "wot"
    npi: 2
  }) {
    credentials
    gender
    name_first
    name_last
    name_middle
    npi
  }
}

2020-03-11T13:57:52.295Z engine stdout {
  timestamp: 'Mar 11 13:57:52.294',
  level: 'ERROR',
  target: 'prisma',
  fields: {
    message: 'PANIC',
    reason: 'column on null constraint violation error',
    file: 'src/libcore/option.rs',
    line: 1188,
    column: 5
  }
}
model providers_individuals {
  credentials String?
  gender      String?
  name_first  String?
  name_last   String?
  name_middle String?
  npi         Int     @id

  @@index([gender], name: "providers_individuals_gender_index")
}
create table providers_individuals
(
        npi integer not null
                constraint providers_individuals_npi_pk
                        primary key
                constraint providers_individuals_providers_npi_fk
                        references providers,
        name_last text,
        name_first text,
        name_middle text,
        credentials text,
        gender text
)
;

create index providers_individuals_gender_index
        on providers_individuals (gender)
;
create table providers
(
        npi integer not null
                constraint providers_npi_pk
                        primary key,
        entity_type text,
        provider_type text,
        address_street_01 text,
        address_street_02 text,
        address_city text,
        address_zip_code text,
        address_state text,
        address_country text,
        address_latitude numeric,
        address_longitude numeric
)
;
janpio commented 4 years ago

The SQL shows that the table providers_individuals has a PK that is also a FK to the table providers. That is currently not supported in Prisma, so test-utils does not have any way to find out about that it should insert an existing providers.id here.