Skip to content

Bug ScanStruct deserializing nullable fields inside tuples #1648

@rbroggi

Description

@rbroggi

Observed

See this reproducer

Expected behaviour

Should properly deserialize nullable fields into pointer fields

Code example

See this PR:

I have created 2 new test cases that shows that the same deserialization works for non-nullable fields and panics for nullable field

Error log

--- FAIL: TestArrayTupleNullableFieldPanic (0.01s)
panic: reflect: call of reflect.Value.Type on zero Value [recovered, repanicked]

goroutine 111 [running]:
testing.tRunner.func1.2({0xad42a0, 0xc00054e2a0})
	/usr/lib/go/src/testing/testing.go:1872 +0x237
testing.tRunner.func1()
	/usr/lib/go/src/testing/testing.go:1875 +0x35b
panic({0xad42a0?, 0xc00054e2a0?})
	/usr/lib/go/src/runtime/panic.go:783 +0x132
reflect.Value.abiTypeSlow({0x0?, 0x0?, 0xc00015f5e0?})
	/usr/lib/go/src/reflect/value.go:2474 +0xee
reflect.Value.typeSlow({0x0?, 0x0?, 0xc00015f618?})
	/usr/lib/go/src/reflect/value.go:2462 +0x1d
reflect.Value.Type(...)
	/usr/lib/go/src/reflect/value.go:2457
reflect.Value.CanConvert({0x0?, 0x0?, 0xd57f88?}, {0xd51bf8, 0xa913c0})
	/usr/lib/go/src/reflect/value.go:3166 +0x51
github.com/ClickHouse/clickhouse-go/v2/lib/column.setJSONFieldValue({0xa913c0?, 0xc00054e298?, 0x41a800?}, {0x0?, 0x0?, 0xc00015f848?})
	/home/rb/repo/efg/clickhouse-go/lib/column/tuple.go:203 +0xb49
github.com/ClickHouse/clickhouse-go/v2/lib/column.(*Tuple).scanStruct(0xc0006981e0, {0xb21ae0?, 0xc00054e288?, 0xc00015f9a8?}, 0x1)
	/home/rb/repo/efg/clickhouse-go/lib/column/tuple.go:370 +0x492
github.com/ClickHouse/clickhouse-go/v2/lib/column.(*Array).scanSliceOfStructs(0xc00003e420, {0xd51bf8, 0xaa42c0}, 0x0)
	/home/rb/repo/efg/clickhouse-go/lib/column/array.go:487 +0x3df
github.com/ClickHouse/clickhouse-go/v2/lib/column.(*Array).scanSliceOfObjects(0xc00003e420, {0xd51bf8, 0xaa42c0}, 0x0)
	/home/rb/repo/efg/clickhouse-go/lib/column/array.go:396 +0x2db
github.com/ClickHouse/clickhouse-go/v2/lib/column.(*Array).scan(0xc000097380?, {0xd51bf8?, 0xaa42c0?}, 0x100d57f88?)
	/home/rb/repo/efg/clickhouse-go/lib/column/array.go:292 +0x3f
github.com/ClickHouse/clickhouse-go/v2/lib/column.(*Array).ScanRow(0xc00003e420, {0xc000097380?, 0xc000088648}, 0x0)
	/home/rb/repo/efg/clickhouse-go/lib/column/array.go:281 +0x116
github.com/ClickHouse/clickhouse-go/v2.scan(0xc000318440, 0x1, {0xc000088660?, 0x2, 0xc000088640?})
	/home/rb/repo/efg/clickhouse-go/scan.go:90 +0x199
github.com/ClickHouse/clickhouse-go/v2.(*rows).Scan(0xc000136480?, {0xc000088660?, 0xa?, 0xc000088520?})
	/home/rb/repo/efg/clickhouse-go/clickhouse_rows.go:78 +0xa5
github.com/ClickHouse/clickhouse-go/v2.(*rows).ScanStruct(0xc00049e2a0, {0xa90a80?, 0xc000088640?})
	/home/rb/repo/efg/clickhouse-go/clickhouse_rows.go:86 +0x71
github.com/ClickHouse/clickhouse-go/v2/tests.TestArrayTupleNullableFieldPanic.func1(0xc000602700, 0x0)
	/home/rb/repo/efg/clickhouse-go/tests/scan_struct_test.go:147 +0x3c4
github.com/ClickHouse/clickhouse-go/v2/tests.TestProtocols.func1(0xc000602700?)
	/home/rb/repo/efg/clickhouse-go/tests/utils.go:846 +0x19
testing.tRunner(0xc000602700, 0xc000548e30)
	/usr/lib/go/src/testing/testing.go:1934 +0xea
created by testing.(*T).Run in goroutine 110
	/usr/lib/go/src/testing/testing.go:1997 +0x465

Details

Environment

  • [ x] clickhouse-go version: latest (master)
  • [ x] Interface: ClickHouse API / database/sql compatible driver
  • [ x] Go version: latest (1.25)
  • [ x] Operating system: any
  • [ x] ClickHouse version: docker version in master of repo
  • [x ] Is it a ClickHouse Cloud? any reproduced in docker container
  • [ x] ClickHouse Server non-default settings, if any: none
  • [ x] CREATE TABLE statements for tables involved: not-applicable
  • [x ] Sample data for all these tables, use clickhouse-obfuscator if necessary

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions