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

fix(i): JSON object default value panic #3156

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions client/definitions.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,6 @@ type FieldDefinition struct {

// If true, this is the primary half of a relation, otherwise is false.
IsPrimaryRelation bool

// DefaultValue contains the default value for this field.
DefaultValue any
}

// NewFieldDefinition returns a new [FieldDefinition], combining the given local and global elements
Expand All @@ -167,7 +164,6 @@ func NewFieldDefinition(local CollectionFieldDescription, global SchemaFieldDesc
RelationName: local.RelationName.Value(),
Typ: global.Typ,
IsPrimaryRelation: kind.IsObject() && !kind.IsArray(),
DefaultValue: local.DefaultValue,
}
}

Expand All @@ -178,7 +174,6 @@ func NewLocalFieldDefinition(local CollectionFieldDescription) FieldDefinition {
ID: local.ID,
Kind: local.Kind.Value(),
RelationName: local.RelationName.Value(),
DefaultValue: local.DefaultValue,
}
}

Expand Down
2 changes: 1 addition & 1 deletion client/document.go
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,7 @@ func (doc *Document) setAndParseObjectType(value map[string]any) error {
}

func (doc *Document) setDefaultValues() error {
for _, field := range doc.collectionDefinition.GetFields() {
for _, field := range doc.collectionDefinition.Description.Fields {
if field.DefaultValue == nil {
continue // no default value to set
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestCollectionDescription_WithDefaultFieldValues(t *testing.T) {
name: String @default(string: "Bob")
age: Int @default(int: 10)
points: Float @default(float: 30)
metadata: JSON @default(json: "{\"value\":1}")
metadata: JSON @default(json: {value: 1})
image: Blob @default(blob: "ff0099")
}
`,
Expand Down Expand Up @@ -66,9 +66,11 @@ func TestCollectionDescription_WithDefaultFieldValues(t *testing.T) {
DefaultValue: "ff0099",
},
{
ID: 5,
Name: "metadata",
DefaultValue: "{\"value\":1}",
ID: 5,
Name: "metadata",
DefaultValue: map[string]any{
"value": float64(1),
},
},
{
ID: 6,
Expand Down
12 changes: 6 additions & 6 deletions tests/integration/mutation/create/with_default_values_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestMutationCreate_WithDefaultValues_NoValuesProvided_SetsDefaultValue(t *t
name: String @default(string: "Bob")
age: Int @default(int: 40)
points: Float @default(float: 10)
metadata: JSON @default(json: "{\"one\":1}")
metadata: JSON @default(json: {tree: "oak"})
image: Blob @default(blob: "ff0099")
}
`,
Expand Down Expand Up @@ -60,7 +60,7 @@ func TestMutationCreate_WithDefaultValues_NoValuesProvided_SetsDefaultValue(t *t
"name": "Bob",
"points": float64(10),
"created": time.Time(time.Date(2000, time.July, 23, 3, 0, 0, 0, time.UTC)),
"metadata": "{\"one\":1}",
"metadata": map[string]any{"tree": "oak"},
"image": "ff0099",
},
},
Expand All @@ -84,7 +84,7 @@ func TestMutationCreate_WithDefaultValues_NilValuesProvided_SetsNilValue(t *test
name: String @default(string: "Bob")
age: Int @default(int: 40)
points: Float @default(float: 10)
metadata: JSON @default(json: "{\"one\":1}")
metadata: JSON @default(json: {tree: "oak"})
image: Blob @default(blob: "ff0099")
}
`,
Expand Down Expand Up @@ -144,7 +144,7 @@ func TestMutationCreate_WithDefaultValues_ValuesProvided_SetsValue(t *testing.T)
name: String @default(string: "Bob")
age: Int @default(int: 40)
points: Float @default(float: 10)
metadata: JSON @default(json: "{\"one\":1}")
metadata: JSON @default(json: {tree: "oak"})
image: Blob @default(blob: "ff0099")
}
`,
Expand All @@ -156,7 +156,7 @@ func TestMutationCreate_WithDefaultValues_ValuesProvided_SetsValue(t *testing.T)
"name": "Alice",
"points": float64(5),
"created": time.Time(time.Date(2024, time.June, 18, 1, 0, 0, 0, time.UTC)),
"metadata": "{\"two\":2}",
"metadata": map[string]any{"tree": "maple"},
"image": "aabb33",
},
},
Expand All @@ -180,7 +180,7 @@ func TestMutationCreate_WithDefaultValues_ValuesProvided_SetsValue(t *testing.T)
"name": "Alice",
"points": float64(5),
"created": time.Time(time.Date(2024, time.June, 18, 1, 0, 0, 0, time.UTC)),
"metadata": "{\"two\":2}",
"metadata": map[string]any{"tree": "maple"},
"image": "aabb33",
},
},
Expand Down
Loading