Prisma1: Go Client Exists on non-existing id cause panic: interface conversion: interface {} is nil, not map[string]interface {}

Created on 25 Sep 2018  路  16Comments  路  Source: prisma/prisma1

Describe the bug
Go Client Exists cause panic

To Reproduce
Steps to reproduce the behavior:

  1. try db.Exists.User, passing a non-existing user id

Expected behavior
panic: interface conversion: interface {} is nil, not map[string]interface {}

Screenshots
snip20180926_22

Versions (please complete the following information):

  • OS: OS X High Sierra
  • prisma CLI: prisma/1.18.0-alpha.3 (darwin-x64) node-v10.5.0
  • Prisma Server: 1.11
bu2-confirmed arecliengo

All 16 comments

This is true outside of just the Exists query. In general the generated go code seems to panic on any type of query failure and is not production ready.

Here you can see it will panic if the database cannot connect.

Error Exec: Post http://localhost:4466/dbaas/local: dial tcp 127.0.0.1:4466: connect: connection refused
Original Unpacked Data Step Exec: map[]
panic: interface conversion: interface {} is nil, not map[string]interface {}

In this case there is an Exec Error that is printed but not returned.

I experienced this issue on a different case where after a clean of my volumes with the "docker rm volume" command the code started to panic whatever the mutation, query, etc. In my case to have a working code again, I did "docker system prune" and "docker image prune"

@sirkay777, @gregwebs, @Sach97 Thanks for raising this. We have released a rewrite of Go client (available in beta version prisma/1.19.0-beta.0 that implements the fix for this, along with other important fixes.

Please give it a go and give us your valuable feedback.

Well I've installed the cli 1.19.0 alpha, git clone examples, docker-compose up, prisma deploy, gqlgen -v, and now it throws :

Unable to bind Post.author to prisma-examples/go-graphql/prisma-client.Post
  no method named author
  no field named author
  Adding resolver method
Unable to bind User.posts to prisma-examples/go-graphql/prisma-client.User
  no method named posts
  no field named posts
  Adding resolver method
/home/sacha/go/src/prisma-examples/go-graphql/server/generated.go
Unable to bind Post.author to prisma-examples/go-graphql/prisma-client.Post
  no method named author
  no field named author
  Adding resolver method
Unable to bind User.posts to prisma-examples/go-graphql/prisma-client.User
  no method named posts
  no field named posts
  Adding resolver method
Skipped resolver: prisma-examples/go-graphql/tmp.Resolver already exists
/home/sacha/go/src/github.com/prisma/prisma-client-lib-go/ast.go:89:12: Builder not declared by package strings
/home/sacha/go/src/github.com/prisma/prisma-client-lib-go/ast.go:22:33: Builder not declared by package strings
/home/sacha/go/src/github.com/prisma/prisma-client-lib-go/ast.go:40:30: Builder not declared by package strings
/home/sacha/go/src/github.com/prisma/prisma-client-lib-go/ast.go:98:32: Builder not declared by package strings
/home/sacha/go/src/github.com/prisma/prisma-client-lib-go/ast.go:115:33: Builder not declared by package strings
/home/sacha/go/src/github.com/prisma/prisma-client-lib-go/ast.go:26:2: invalid operation: b (variable of type *invalid type) has no field or method WriteByte
/home/sacha/go/src/github.com/prisma/prisma-client-lib-go/ast.go:29:4: invalid operation: b (variable of type *invalid type) has no field or method WriteString
/home/sacha/go/src/github.com/prisma/prisma-client-lib-go/ast.go:31:3: invalid operation: b (variable of type *invalid type) has no field or method WriteString
/home/sacha/go/src/github.com/prisma/prisma-client-lib-go/ast.go:32:3: invalid operation: b (variable of type *invalid type) has no field or method WriteString
/home/sacha/go/src/github.com/prisma/prisma-client-lib-go/ast.go:33:3: invalid operation: b (variable of type *invalid type) has no field or method WriteString
/home/sacha/go/src/github.com/prisma/prisma-client-lib-go/ast.go:35:2: invalid operation: b (variable of type *invalid type) has no field or method WriteByte
/home/sacha/go/src/github.com/prisma/prisma-client-lib-go/ast.go:43:3: invalid operation: b (variable of type *invalid type) has no field or method WriteByte
/home/sacha/go/src/github.com/prisma/prisma-client-lib-go/ast.go:66:8: Builder not declared by package strings
/home/sacha/go/src/github.com/prisma/prisma-client-lib-go/ast.go:69:3: invalid operation: b (variable of type *invalid type) has no field or method WriteString
/home/sacha/go/src/github.com/prisma/prisma-client-lib-go/ast.go:71:3: invalid operation: b (variable of type *invalid type) has no field or method WriteString
/home/sacha/go/src/github.com/prisma/prisma-client-lib-go/ast.go:73:3: invalid operation: b (variable of type *invalid type) has no field or method WriteString
/home/sacha/go/src/github.com/prisma/prisma-client-lib-go/ast.go:78:2: invalid operation: b (variable of type *invalid type) has no field or method WriteByte
/home/sacha/go/src/github.com/prisma/prisma-client-lib-go/ast.go:79:2: invalid operation: b (variable of type *invalid type) has no field or method WriteString
/home/sacha/go/src/github.com/prisma/prisma-client-lib-go/ast.go:81:2: invalid operation: b (variable of type *invalid type) has no field or method WriteString
/home/sacha/go/src/github.com/prisma/prisma-client-lib-go/ast.go:83:2: invalid operation: b (variable of type *invalid type) has no field or method WriteByte
/home/sacha/go/src/github.com/prisma/prisma-client-lib-go/ast.go:85:9: invalid operation: b (variable of type *invalid type) has no field or method String
/home/sacha/go/src/github.com/prisma/prisma-client-lib-go/ast.go:99:2: invalid operation: b (variable of type *invalid type) has no field or method WriteString
/home/sacha/go/src/github.com/prisma/prisma-client-lib-go/ast.go:116:2: invalid operation: b (variable of type *invalid type) has no field or method WriteString
/home/sacha/go/src/github.com/prisma/prisma-client-lib-go/ast.go:118:2: invalid operation: b (variable of type *invalid type) has no field or method WriteString
/home/sacha/go/src/github.com/prisma/prisma-client-lib-go/ast.go:120:2: invalid operation: b (variable of type *invalid type) has no field or method WriteString
validation failed: couldn't load packages due to errors: github.com/prisma/prisma-client-lib-go

And if I do go get -v github.com/prisma/prisma-client-lib-go, it throws :

../../github.com/prisma/prisma-client-lib-go/ast.go:22:33: undefined: strings.Builder
../../github.com/prisma/prisma-client-lib-go/ast.go:40:30: undefined: strings.Builder
../../github.com/prisma/prisma-client-lib-go/ast.go:66:8: undefined: strings.Builder
../../github.com/prisma/prisma-client-lib-go/ast.go:89:12: undefined: strings.Builder
../../github.com/prisma/prisma-client-lib-go/ast.go:98:32: undefined: strings.Builder
../../github.com/prisma/prisma-client-lib-go/ast.go:115:33: undefined: strings.Builder

Go version : go1.9.7 linux/amd64

"strings.Builder" was added in Go 1.10
Would it be possible for you to update your Go version?

@divyenduz works great! thanks!

"strings.Builder" was added in Go 1.10
Would it be possible for you to update your Go version?

Thank's a lot @divyenduz it doesn't throw the prisma-client-lib-go strings.builder error anymore and the server run on the example. As soon I've tested my schema I'll give my feedback.

Is it normal that I don't have autocompletion on relations like for example r.Prisma.User(...).Posts() since the fix ?

@Sach97 : You should have the autocompletions! Can you share your datamodel.prisma and tell me the steps to reproduce it? I can give it a go.

I just added a type Tag to the go-graphql example to test my question posted on the forum.

scalar DateTime

type Query {
  feed: [Post!]!
  drafts: [Post!]!
  post(id: ID!): Post
}

type Mutation {
  createDraft(title: String!, content: String!, authorEmail: String!): Post!
  createUser(email: String!, name: String!): User!
  deletePost(id: ID!): Post
  publish(id: ID!): Post
  createTag(id:ID!, name: [String!]!): Tag!
}

type Post {
  id: ID!
  createdAt: DateTime!
  updatedAt: DateTime!
  isPublished: Boolean!
  title: String!
  content: String!
  author: User!
  tags: [Tag!]!
}

type Tag {
  id: ID!
  name: String!
  taggedOn: Post!
}

type User {
  id: ID!
  email: String!
  name: String!
  posts: [Post!]!
}

But even with the original schema I don't have autocompletion (mutation and queries are working). I can have it by retrieving the address with "&" inf front of prisma.UserWhereUniqueInput but it wil break. The code generates correctly the CreateTag types on generated.go and prisma.go but I don't have autocompletion for it either on my resolver.go (I have declared it correctly in gqlgen.yml)

https://github.com/prisma/prisma-examples/blob/6f607d12b57af53b6af4b1a2e3a23a8d194c2eb2/go-graphql/server/resolver.go#L78-L80

@Sach97 : Interesting, can you please create a separate issue for this? https://github.com/prisma/prisma/issues/new/choose

As it is different from the original issue on this thread 馃檹

I've just posted my issue #3294 @divyenduz. I tried to be the more precise possible.

Looks much better! Docs still need to be updated.

@gregwebs Thanks! we will update the docs once this hits stable ETA for that is Oct 23rd.

I think this can be closed as fixed now.

This is released in the stable 1.19.0 - npm install -g prisma or brew tap prisma/prisma && brew install prisma 馃帀

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sorenbs picture sorenbs  路  3Comments

notrab picture notrab  路  3Comments

schickling picture schickling  路  3Comments

schickling picture schickling  路  3Comments

ragnorc picture ragnorc  路  3Comments