prisma icon indicating copy to clipboard operation
prisma copied to clipboard

TypeError: outputType.fields is not iterable

Open sk1122 opened this issue 2 years ago • 3 comments

Bug description

I am prisma with postgresql with below schema

Debugged this error a little bit inside compile @prisma/client code and found this (this is a computer generated code though)

In selectionToFields(dmmf, selection, schemaField, path7, context3) function, we have this line of code inside reduce method on Object.entries(selection)

const field = outputType.fieldMap ? outputType.fieldMap[name] : outputType.fields.find((f) => f.name === name);

after console.log, we get this

{
  name: 'createOneID',
  args: [
    {
      name: 'data',
      isRequired: true,
      isNullable: false,
      inputTypes: [Array]
    }
  ],
  isNullable: false,
  outputType: {
    type: 'ID',
    namespace: 'model',
    location: 'outputObjectTypes',
    isList: false
  }
} 

If you look, outputType.type is a string but in other cases it is an object

How to reproduce

  1. Copy my schema from above
  2. Initialize postgresql database
  3. run above create query with required params

Expected behavior

Should create the entity in database

Prisma information

// Add your schema.prisma
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

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

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

model ArweaveTx {
  id           String @id @default(uuid())
  txId         String
  txCommitment String
  ID           ID?
}

model ID {
  id          String    @id
  identifier  String
  provider    String
  default     Json
  others      Json[]
  arweaveTxId String
  arweaveTx   ArweaveTx @relation(fields: [arweaveTxId], references: [id])

  @@unique([arweaveTxId])
}

// Add your code using Prisma Client

export const storeId = async (id: Prisma.IDCreateInput) => {
	console.log(id)
	const data = await prisma.iD.create({
		data: id
	})

	return data
}

Environment & setup

  • OS: Ubuntu LTS
  • Database: PostgreSQL
  • Node.js version: v16.17.0

Prisma Version

prisma                  : 4.3.1
@prisma/client          : 4.3.1
Current platform        : debian-openssl-1.1.x
Query Engine (Node-API) : libquery-engine c875e43600dfe042452e0b868f7a48b817b9640b (at node_modules/@prisma/engines/libquery_engine-debian-openssl-1.1.x.so.node)
Migration Engine        : migration-engine-cli c875e43600dfe042452e0b868f7a48b817b9640b (at node_modules/@prisma/engines/migration-engine-debian-openssl-1.1.x)
Introspection Engine    : introspection-core c875e43600dfe042452e0b868f7a48b817b9640b (at node_modules/@prisma/engines/introspection-engine-debian-openssl-1.1.x)
Format Binary           : prisma-fmt c875e43600dfe042452e0b868f7a48b817b9640b (at node_modules/@prisma/engines/prisma-fmt-debian-openssl-1.1.x)
Format Wasm             : @prisma/prisma-fmt-wasm 4.3.0-32.c875e43600dfe042452e0b868f7a48b817b9640b
Default Engines Hash    : c875e43600dfe042452e0b868f7a48b817b9640b
Studio                  : 0.473.0

sk1122 avatar Sep 17 '22 21:09 sk1122

Solved this issue, was because of my database name, apparently it can't be ID

sk1122 avatar Sep 17 '22 23:09 sk1122

That sounds like a bug then.

Can you confirm again, with a database name ID in PostgreSQL things failed, but when you changed it to something else it worked?

janpio avatar Sep 19 '22 09:09 janpio

Yes, it failed with database name ID and not when I changed it to ObjId

sk1122 avatar Sep 20 '22 10:09 sk1122

I just realized: I think with "database name" you mean the name of the table in the database, which influences the name of the model in Prisma Schema?

janpio avatar Sep 23 '22 11:09 janpio

oh, my bad, yes i was referring to table name, sorry, it just slept out of my mind

sk1122 avatar Sep 23 '22 16:09 sk1122

Ran into the same error on Prisma v4.6.1; MacOS

{
  id: 'id',
  identifier: 'identifier',
  provider: 'provider',
  default: '',
  arweaveTx: {}
}
TypeError: outputType.fields is not iterable

and can confirm that the error disappears when renaming it to not ID

Druue avatar Nov 28 '22 13:11 Druue