Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@default directive accepts invalid values #3133

Closed
islamaliev opened this issue Oct 15, 2024 · 0 comments · Fixed by #3137
Closed

@default directive accepts invalid values #3133

islamaliev opened this issue Oct 15, 2024 · 0 comments · Fixed by #3137
Assignees
Labels
bug Something isn't working release/blocker This issue is blocking the next release
Milestone

Comments

@islamaliev
Copy link
Contributor

islamaliev commented Oct 15, 2024

Add a schema with invalid default value:

$ defradb client schema add 'type User { name: String, active: Boolean @default(bool: blah)}'

It competes without errors. When you create a doc arterwards:

$ defradb client collection create '{ "name": "John" }'

You get a panic:

panic: interface conversion: interface {} is string, not bool

goroutine 1 [running]:
github.com/sourcenetwork/defradb/client.getBool({0x108e5b540?, 0x14001d5bcd0?})
	github.com/sourcenetwork/defradb/client/document.go:386 +0x94
github.com/sourcenetwork/defradb/client.validateFieldSchema({0x108e5b540, 0x14001d5bcd0}, {{0x14001d71d68, 0x6}, 0x1, {0x10972cfb8, 0x10bd71590}, {0x0, 0x0}, 0x1, ...})
	github.com/sourcenetwork/defradb/client/document.go:291 +0xa58
github.com/sourcenetwork/defradb/client.(*Document).Set(0x140012151e0, {0x14001d71d68, 0x6}, {0x108e5b540, 0x14001d5bcd0})
	github.com/sourcenetwork/defradb/client/document.go:736 +0x53c
github.com/sourcenetwork/defradb/client.(*Document).setDefaultValues(0x140012151e0)
	github.com/sourcenetwork/defradb/client/document.go:778 +0xb8
github.com/sourcenetwork/defradb/client.newEmptyDoc({{{0x1, {0x14001d71ad0, 0x4}}, 0x1, 0x1, {0x14001d82340, 0x3b}, {0x10beea120, 0x0, 0x0}, ...}, ...})
	github.com/sourcenetwork/defradb/client/document.go:109 +0xa8
github.com/sourcenetwork/defradb/client.NewDocFromJSON({_, _, _}, {{{0x1, {0x14001d71ad0, 0x4}}, 0x1, 0x1, {0x14001d82340, 0x3b}, ...}, ...})
	github.com/sourcenetwork/defradb/client/document.go:170 +0x4c
github.com/sourcenetwork/defradb/cli.MakeCollectionCreateCommand.func1(0x14001d65208, {0x14001d5aa80?, 0x1?, 0x107f2b1bc?})
	github.com/sourcenetwork/defradb/cli/collection_create.go:100 +0x26c
github.com/spf13/cobra.(*Command).execute(0x14001d65208, {0x14001d5aa50, 0x1, 0x1})
	github.com/spf13/[email protected]/command.go:985 +0x840
github.com/spf13/cobra.(*Command).ExecuteC(0x14001d6db08)
	github.com/spf13/[email protected]/command.go:1117 +0x344
github.com/spf13/cobra.(*Command).Execute(0x10bd03388?)
	github.com/spf13/[email protected]/command.go:1041 +0x1c
main.main()
	github.com/sourcenetwork/defradb/cmd/defradb/main.go:23 +0x20

Note:
With not matching types:

$ defradb client schema add 'type User { name: String, age: Int @default(int: "1")}'

It doesn't panic:

$ defradb client collection create '{ "name": "John" }'
Error: unexpected type. Property: field, Expected: int64, Actual: string

But it needs to be caught on schema creation.

@islamaliev islamaliev added the bug Something isn't working label Oct 15, 2024
@islamaliev islamaliev added this to the DefraDB v0.14 milestone Oct 15, 2024
@nasdf nasdf self-assigned this Oct 15, 2024
@nasdf nasdf closed this as completed in 6cc39a7 Oct 15, 2024
@jsimnz jsimnz added the release/blocker This issue is blocking the next release label Oct 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working release/blocker This issue is blocking the next release
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants