From 6942d9e07b3cc3c4a75620b5c79a193a345e851f Mon Sep 17 00:00:00 2001 From: Antoni Stachowski Date: Wed, 31 Jul 2024 11:53:18 +0200 Subject: [PATCH] Fix null in structured types arrays regression (#1187) * Reverted option check changes * Change option enabled to pass context by pointer * Performance improvement --------- Co-authored-by: Dawid Heyman --- structured_type.go | 22 ++++++++++++++-------- structured_type_read_test.go | 1 - 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/structured_type.go b/structured_type.go index 17b7b91e7..7fdf174fa 100644 --- a/structured_type.go +++ b/structured_type.go @@ -1150,8 +1150,8 @@ func (st *structuredType) fieldMetadataByFieldName(fieldName string) (fieldMetad return fieldMetadata{}, errors.New("no metadata for field " + fieldName) } -func optionEnabled(ctx context.Context, option contextKey) bool { - v := ctx.Value(option) +func structuredTypesEnabled(ctx context.Context) bool { + v := ctx.Value(enableStructuredTypes) if v == nil { return false } @@ -1159,16 +1159,22 @@ func optionEnabled(ctx context.Context, option contextKey) bool { return ok && d } -func structuredTypesEnabled(ctx context.Context) bool { - return optionEnabled(ctx, enableStructuredTypes) -} - func mapValuesNullableEnabled(ctx context.Context) bool { - return optionEnabled(ctx, mapValuesNullable) + v := ctx.Value(mapValuesNullable) + if v == nil { + return false + } + d, ok := v.(bool) + return ok && d } func arrayValuesNullableEnabled(ctx context.Context) bool { - return optionEnabled(ctx, arrayValuesNullable) + v := ctx.Value(arrayValuesNullable) + if v == nil { + return false + } + d, ok := v.(bool) + return ok && d } func getSfFieldName(field reflect.StructField) string { diff --git a/structured_type_read_test.go b/structured_type_read_test.go index 906ff248f..1d4911916 100644 --- a/structured_type_read_test.go +++ b/structured_type_read_test.go @@ -1757,7 +1757,6 @@ func TestArraysWithNullValues(t *testing.T) { } else { assertDeepEqualE(t, tc.actual, tc.expected) } - fmt.Printf("%v", reflect.TypeOf(tc.actual)) }) } })