Skip to content

Fix support for equality query on key field#40

Open
mrpotes wants to merge 1 commit intonshmura:masterfrom
mrpotes:master
Open

Fix support for equality query on key field#40
mrpotes wants to merge 1 commit intonshmura:masterfrom
mrpotes:master

Conversation

@mrpotes
Copy link
Copy Markdown

@mrpotes mrpotes commented Jan 15, 2020

An equality check for a key field was failing with a panic if the optional project and namespace were not supplied, and with a datastore client error if they were provided.

Panic output was:

panic: interface conversion: gql.Expression is nil, not string

goroutine 1 [running]:
github.com/nshmura/dsio/gql.(*yyParserImpl).Parse(0xc0002daa80, 0xbbbae0, 0xc0002e2ac0, 0x0)
	yaccpar:735 +0x549b
github.com/nshmura/dsio/gql.yyParse(...)
	yaccpar:153
github.com/nshmura/dsio/gql.(*Lexer).Parse(0xc0002e2ac0, 0xc00030a520, 0x1000)
	parser.go.y:737 +0x5e
github.com/nshmura/dsio/action.parseGQL(0x7fff97a33dcd, 0x60, 0xc0002632a0, 0x448b8e, 0xc0000bdab2)
	/home/james/dev/go/pkg/mod/github.com/nshmura/dsio@v0.0.0-20180122043609-0454626fc6fd/action/query.go:102 +0x1d6
github.com/nshmura/dsio/action.getKindQuery(0x7fff97a33d09, 0x54, 0x7fff97a33d6b, 0x19, 0x7fff97a33d91, 0xf, 0x0, 0x7fff97a33dcd, 0x60, 0xa411376f0f80abb6, ...)
	/home/james/dev/go/pkg/mod/github.com/nshmura/dsio@v0.0.0-20180122043609-0454626fc6fd/action/query.go:85 +0x3f
github.com/nshmura/dsio/action.Query(0x7fff97a33d09, 0x54, 0x7fff97a33d6b, 0x19, 0x7fff97a33d91, 0xf, 0x0, 0x7fff97a33dcd, 0x60, 0x7fff97a33daa, ...)
	/home/james/dev/go/pkg/mod/github.com/nshmura/dsio@v0.0.0-20180122043609-0454626fc6fd/action/query.go:45 +0xc7
main.main.func2(0xc0000eb340, 0x0, 0xc000282ab0)
	/home/james/dev/go/pkg/mod/github.com/nshmura/dsio@v0.0.0-20180122043609-0454626fc6fd/dsio.go:175 +0x33f
github.com/urfave/cli.HandleAction(0x9e8d40, 0xb10b38, 0xc0000eb340, 0xc0000eb340, 0x0)
	/home/james/dev/go/pkg/mod/github.com/urfave/cli@v1.22.2/app.go:523 +0xbe
github.com/urfave/cli.Command.Run(0xae0a6c, 0x5, 0x0, 0x0, 0x0, 0x0, 0x0, 0xae7db4, 0x10, 0x0, ...)
	/home/james/dev/go/pkg/mod/github.com/urfave/cli@v1.22.2/command.go:174 +0x51c
github.com/urfave/cli.(*App).Run(0xc0003001c0, 0xc0000c6000, 0xf, 0xf, 0x0, 0x0)
	/home/james/dev/go/pkg/mod/github.com/urfave/cli@v1.22.2/app.go:276 +0x725
main.main()
	/home/james/dev/go/pkg/mod/github.com/nshmura/dsio@v0.0.0-20180122043609-0454626fc6fd/dsio.go:184 +0xa80

Datastore error was:

[ERROR] datastore: bad query filter value type: invalid Value type gql.KeyLiteralExpr

The first is fixed by defaulting the project and namespace to an empty string if not specified (a string cannot be set to nil).

The latter is fixed by translating the gql.KeyLiteralExpr into a datastore.Key in the equality branch of the query building.

It's not clear from the datastore client docs what one should do with the project ID if it is specified in the KEY(...) GQL expression, so this is left unimplemented at present.

@mrpotes mrpotes requested a review from nshmura January 15, 2020 12:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants