prisma / prisma-test-utils

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

TypeError e.map is not a function #29

Closed divyenduz closed 4 years ago

divyenduz commented 4 years ago

For the schema: https://github.com/prisma/database-schema-examples/blob/master/postgres/basic-blog/schema.sql

Logs from test-utils just before the failure:

2020-03-06T21:47:40.352Z prisma-client Requests:
2020-03-06T21:47:40.353Z prisma-client [
  'mutation {\n' +
    '  createOneauthors(data: {\n' +
    '    name: "ofosid"\n' +
    '  }) {\n' +
    '    id\n' +
    '    name\n' +
    '    authors_blogs {\n' +
    '\n' +
    '    }\n' +
    '  }\n' +
    '}'
]
2020-03-06T21:47:40.425Z engine {
  error: TypeError: e.map is not a function
      at /home/runner/work/introspection-engine-output/introspection-engine-output/clients/postgresql_public_test_utils/basic-blog/runtime/index.js:1:16669
      at processTicksAndRejections (internal/process/task_queues.js:97:5)
      at Dataloader.loader (/home/runner/work/introspection-engine-output/introspection-engine-output/clients/postgresql_public_test_utils/basic-blog/index.js:56:23)
}

This is most likely happening because authors_blogs model has no scalar on it and test utils produces an incorrect client call for that (empty selection set).

@maticzav does this issue description make sense?


Internal notes:

Test utils database(s) affected:

maticzav commented 4 years ago

@divyenduz yup, I think this is it.

janpio commented 4 years ago

The log you link to @divyenduz does not show the problem from the issue.

because authors_blogs model has no scalar on it

What does that mean?

divyenduz commented 4 years ago

The log you link to @divyenduz does not show the problem from the issue.

I don't follow, it has the text "error: TypeError: e.map is not a function", right?

because authors_blogs model has no scalar on it

I meant that the model generated for this table authors_blogs does not have any scalar fields

model authors_blogs {
  author_id authors
  blog_id   blogs

  @@unique([author_id, blog_id], name: "authors_blogs_author_id_blog_id_key")
}

Does that make sense now?

janpio commented 4 years ago

The log you link to @divyenduz does not show the problem from the issue.

I don't follow, it has the text "error: TypeError: e.map is not a function", right?

No, the linked log does not. Current content when I open the file:

/home/runner/work/introspection-engine-output/introspection-engine-output/clients/postgresql_public_test_utils/basic-blog
===start client generation===
2020-03-09T16:07:04.823Z prisma-client {
  engineConfig: {
    cwd: '/home/runner/work/introspection-engine-output/introspection-engine-output/postgresql_public_test_utils',
    debug: false,
    datamodelPath: '/home/runner/work/introspection-engine-output/introspection-engine-output/clients/postgresql_public_test_utils/basic-blog/schema.prisma',
    prismaPath: undefined,
    datasources: [],
    generator: {
      name: 'client',
      provider: 'prisma-client-js',
      output: '/home/runner/work/introspection-engine-output/introspection-engine-output/clients/postgresql_public_test_utils/basic-blog',
      binaryTargets: [],
      config: {}
    },
    showColors: false,
    logLevel: undefined,
    logQueries: undefined,
    env: {},
    flags: []
  }
}
===end client generation===
===start seed===
2020-03-09T16:07:04.905Z prisma-client Prisma Client call:
2020-03-09T16:07:04.906Z prisma-client prisma.authors.create({
  data: {
    name: 'ofosid'
  }
})
2020-03-09T16:07:04.906Z prisma-client Generated request:
2020-03-09T16:07:04.906Z prisma-client mutation {
  createOneauthors(data: {
    name: "ofosid"
  }) {
    id
    name
  }
}

2020-03-09T16:07:04.909Z engine {
  PRISMA_DML_PATH: '/home/runner/work/introspection-engine-output/introspection-engine-output/clients/postgresql_public_test_utils/basic-blog/schema.prisma',
  PORT: '44187',
  RUST_BACKTRACE: '1',
  RUST_LOG: 'info',
  OVERWRITE_DATASOURCES: '[]'
}
2020-03-09T16:07:04.909Z engine {
  cwd: '/home/runner/work/introspection-engine-output/introspection-engine-output/postgresql_public_test_utils'
}
2020-03-09T16:07:04.912Z getos { version: 'OpenSSL 1.1.1d  10 Sep 2019\n' }
2020-03-09T16:07:04.912Z getos { ls: '' }
2020-03-09T16:07:04.914Z getos { platform: 'linux', libssl: '1.1.x' }
2020-03-09T16:07:04.914Z plusX Execution permissions of /home/runner/work/introspection-engine-output/introspection-engine-output/clients/postgresql_public_test_utils/basic-blog/runtime/query-engine-debian-openssl-1.1.x are fine
2020-03-09T16:07:04.914Z engine { flags: [ '--enable-raw-queries' ] }
2020-03-09T16:07:04.956Z engine stderr Printing to stderr for debugging
2020-03-09T16:07:04.957Z engine stderr Listening on 127.0.0.1:44187
2020-03-09T16:07:04.958Z engine stdout {
  timestamp: 'Mar 09 16:07:04.958',
  level: 'INFO',
  target: 'quaint::pooled',
  fields: { message: 'Starting a postgresql pool with 5 connections.' }
}
2020-03-09T16:07:04.963Z engine stdout {
  timestamp: 'Mar 09 16:07:04.962',
  level: 'INFO',
  target: 'prisma::server',
  fields: {
    message: 'Started http server on 127.0.0.1:44187',
    'log.target': 'prisma::server',
    'log.module_path': 'prisma::server',
    'log.file': 'query-engine/prisma/src/server.rs',
    'log.line': 95
  }
}
2020-03-09T16:07:06.166Z prisma-client Prisma Client call:
2020-03-09T16:07:06.166Z prisma-client prisma.authors.create({
  data: {
    name: 'daej'
  }
})
2020-03-09T16:07:06.166Z prisma-client Generated request:
2020-03-09T16:07:06.166Z prisma-client mutation {
  createOneauthors(data: {
    name: "daej"
  }) {
    id
    name
  }
}

2020-03-09T16:07:06.792Z prisma-client Prisma Client call:
2020-03-09T16:07:06.792Z prisma-client prisma.blogs.create({
  data: {
    name: 'wocu',
    viewcount: 888
  }
})
2020-03-09T16:07:06.792Z prisma-client Generated request:
2020-03-09T16:07:06.792Z prisma-client mutation {
  createOneblogs(data: {
    name: "wocu"
    viewcount: 888
  }) {
    id
    name
    viewcount
  }
}

2020-03-09T16:07:07.420Z prisma-client Prisma Client call:
2020-03-09T16:07:07.420Z prisma-client prisma.blogs.create({
  data: {
    name: 'gafgohrak',
    viewcount: -1908
  }
})
2020-03-09T16:07:07.421Z prisma-client Generated request:
2020-03-09T16:07:07.421Z prisma-client mutation {
  createOneblogs(data: {
    name: "gafgohrak"
    viewcount: -1908
  }) {
    id
    name
    viewcount
  }
}

2020-03-09T16:07:08.049Z prisma-client Prisma Client call:
2020-03-09T16:07:08.049Z prisma-client prisma.authors_blogs.create({
  data: {
    author_id: {
      connect: {
        id: 1
      }
    },
    blog_id: {
      connect: {
        id: 1
      }
    }
  },
  include: {
    author_id: true,
    blog_id: true
  }
})
2020-03-09T16:07:08.049Z prisma-client Generated request:
2020-03-09T16:07:08.049Z prisma-client mutation {
  createOneauthors_blogs(data: {
    author_id: {
      connect: {
        id: 1
      }
    }
    blog_id: {
      connect: {
        id: 1
      }
    }
  }) {
    author_id {
      id
      name
    }
    blog_id {
      id
      name
      viewcount
    }
  }
}

2020-03-09T16:07:09.392Z prisma-client Prisma Client call:
2020-03-09T16:07:09.392Z prisma-client prisma.authors_blogs.create({
  data: {
    author_id: {
      connect: {
        id: 1
      }
    },
    blog_id: {
      connect: {
        id: 1
      }
    }
  },
  include: {
    author_id: true,
    blog_id: true
  }
})
2020-03-09T16:07:09.392Z prisma-client Generated request:
2020-03-09T16:07:09.392Z prisma-client mutation {
  createOneauthors_blogs(data: {
    author_id: {
      connect: {
        id: 1
      }
    }
    blog_id: {
      connect: {
        id: 1
      }
    }
  }) {
    author_id {
      id
      name
    }
    blog_id {
      id
      name
      viewcount
    }
  }
}

2020-03-09T16:07:10.205Z printStack callsite Error
    at Object.s [as authors_blogs] (/home/runner/work/introspection-engine-output/introspection-engine-output/clients/postgresql_public_test_utils/basic-blog/runtime/index.js:1:44468)
    at Object.n.<computed> [as create] (/home/runner/work/introspection-engine-output/introspection-engine-output/clients/postgresql_public_test_utils/basic-blog/runtime/index.js:1:46094)
    at /home/runner/work/introspection-engine-output/prisma-test-utils/src/static/seed.ts:924:45
    at Generator.next (<anonymous>)
    at /home/runner/work/introspection-engine-output/prisma-test-utils/dist/static/seed.js:8:71
    at new Promise (<anonymous>)
    at __awaiter (/home/runner/work/introspection-engine-output/prisma-test-utils/dist/static/seed.js:4:12)
    at iterate (/home/runner/work/introspection-engine-output/prisma-test-utils/dist/static/seed.js:633:24)
    at /home/runner/work/introspection-engine-output/prisma-test-utils/src/static/seed.ts:947:30
    at Generator.next (<anonymous>)
PrismaClientKnownRequestError: 
Invalid `prisma.authors_blogs.create()` invocation in
/home/runner/work/introspection-engine-output/prisma-test-utils/src/static/seed.ts:924:45

Unique constraint failed on the fields: (`author_id`,`blog_id`)
    at PrismaClientFetcher.request (/home/runner/work/introspection-engine-output/introspection-engine-output/clients/postgresql_public_test_utils/basic-blog/runtime/index.js:1:47071)
    at processTicksAndRejections (internal/process/task_queues.js:97:5) {
  code: 'P2002',
  meta: { target: [ 'author_id', 'blog_id' ] }
}
===end seed===
2020-03-09T16:07:10.208Z engine Stopping Prisma engine
2020-03-09T16:07:10.242Z getos { version: 'OpenSSL 1.1.1d  10 Sep 2019\n' }
2020-03-09T16:07:10.242Z getos { ls: '' }
2020-03-09T16:07:10.242Z getos { platform: 'linux', libssl: '1.1.x' }
janpio commented 4 years ago

Does that make sense now?

No. The "Logs from test-utils just before the failure:" snippet you posted above mentions createOneauthors, which points to model authors. authors_blogs has an @@unique which means it works with P2, and I see no reason why test-utils should not be able to (unless there is some limitation that was not mentioned here yet).

divyenduz commented 4 years ago

No, the linked log does not.

The linked logged is a link on the branch, not a permalink, its contents are subjected to change. A permalink to a failing log is this one.

In the future, I will link both permalink and branch link (to check quickly, if something is fixed)

snippet you posted above mentions createOneauthors, which points to model authors

That is (or was) the correct line of the error, let me extract the query from the logs in my first comment to explain further:

image

As you can see in this image, the generated GraphQL query for the model authors was incorrect.

janpio commented 4 years ago

Doesn't this mean that test-utils is creating a Prisma Client call with missing data, which gets transformed into a broken query to the QE which is then somehow causing the error in Prisma Client (probably because the QE is returning something unexpected)?

The log should include the Prisma Client call now as well. We should rerun this so we have all the context. (Related: The QE can also log all the queries it is sending, right? We should probably have that logged here as well to understand what it is trying to do)

divyenduz commented 4 years ago

I think this mutation log is already coming from client and not test-utils. I will post the client call here if I see it again or close this issue if this is no longer present in any logs in this form.

janpio commented 4 years ago

I think this mutation log is already coming from client and not test-utils.

Yes, but I expect this to be caused by what test-utils sends into Client - not Client messing something up really.

divyenduz commented 4 years ago

I agree with that, hence, I created the issue here. I will clean it up as I have more information.

divyenduz commented 4 years ago

This issue is not present anymore on the latest run.