Skip to content

datatypes.JSON field doesn't work with numbers on SQLite #35

@glothriel

Description

@glothriel

The following test case should pass:

{
			name:    "Nested JSON field",
			baseURL: "/nested_json_field",
			okBodies: []map[string]any{
				{"value": 1},
				{"value": 1.337},
			},
			okResponses: []map[string]any{
				{"value": 1.0},
				{"value": 1.337},
			},
			router: func() *gin.Engine {
				return registerModel[NestedJSONModel]("/nested_json_field", dialector)
			},
		},

but currently it fails with:

[0.094ms] [rows:1] SELECT * FROM `nested_json_models` WHERE id = "6d7d3dd6-b091-4491-9285-632293fa5f0d" ORDER BY `nested_json_models`.`id` LIMIT 1
time="2025-02-20T22:05:09+01:00" level=error msg="Unexpected error of type *fmt.wrapError: sql: Scan error on column index 3, name \"value\": Failed to unmarshal JSONB value:1.337"
--- FAIL: TestSQLite (0.13s)
    --- FAIL: TestSQLite/Nested_JSON_field (0.02s)
        --- FAIL: TestSQLite/Nested_JSON_field/Nested_JSON_field (0.00s)
            integration.go:130: 
                        Error Trace:    /home/kosto/Projects/gin-rest-framework/pkg/integration/integration.go:130
                        Error:          Not equal: 
                                        expected: 200
                                        actual  : 500
                        Test:           TestSQLite/Nested_JSON_field/Nested_JSON_field
        --- FAIL: TestSQLite/Nested_JSON_field/Nested_JSON_field#01 (0.00s)
            integration.go:130: 
                        Error Trace:    /home/kosto/Projects/gin-rest-framework/pkg/integration/integration.go:130
                        Error:          Not equal: 
                                        expected: 200
                                        actual  : 500
                        Test:           TestSQLite/Nested_JSON_field/Nested_JSON_field#01
        --- FAIL: TestSQLite/Nested_JSON_field/Nested_JSON_field#04 (0.00s)
            integration.go:130: 
                        Error Trace:    /home/kosto/Projects/gin-rest-framework/pkg/integration/integration.go:130
                        Error:          Not equal: 
                                        expected: 200
                                        actual  : 500
                        Test:           TestSQLite/Nested_JSON_field/Nested_JSON_field#04
        --- FAIL: TestSQLite/Nested_JSON_field/Nested_JSON_field#05 (0.00s)
            integration.go:130: 
                        Error Trace:    /home/kosto/Projects/gin-rest-framework/pkg/integration/integration.go:130
                        Error:          Not equal: 
                                        expected: 200
                                        actual  : 500
                        Test:           TestSQLite/Nested_JSON_field/Nested_JSON_field#05

It's worth to note, that the case passes on PostgreSQL

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions