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

contrib/drivers/pgsql: write error with json field #3671

Closed
tiglog opened this issue Jul 1, 2024 · 2 comments · Fixed by #3742
Closed

contrib/drivers/pgsql: write error with json field #3671

tiglog opened this issue Jul 1, 2024 · 2 comments · Fixed by #3742
Labels
bug It is confirmed a bug, but don't worry, we'll handle it. done This issue is done, which may be release in next version.

Comments

@tiglog
Copy link

tiglog commented Jul 1, 2024

Go version

go version go1.21.9 linux/amd64

GoFrame version

2.7.2

Can this bug be reproduced with the latest release?

Option Yes

What did you do?

diff --git a/contrib/drivers/pgsql/pgsql_z_unit_issue_test.go b/contrib/drivers/pgsql/pgsql_z_unit_issue_test.go
index 492826c21..b109313a9 100644
--- a/contrib/drivers/pgsql/pgsql_z_unit_issue_test.go
+++ b/contrib/drivers/pgsql/pgsql_z_unit_issue_test.go
@@ -78,8 +78,9 @@ func Test_Issue3330(t *testing.T) {
 // https:/gogf/gf/issues/3632
 func Test_Issue3632(t *testing.T) {
        type Member struct {
-               One []int64    `json:"one" orm:"one"`
-               Two [][]string `json:"two" orm:"two"`
+               One   []int64    `json:"one" orm:"one"`
+               Two   [][]string `json:"two" orm:"two"`
+               Three []string   `json:"tree" orm:"three"`
        }
        var (
                sqlText = gtest.DataContent("issues", "issue3632.sql")
@@ -94,8 +95,9 @@ func Test_Issue3632(t *testing.T) {
                var (
                        dao    = db.Model(table)
                        member = Member{
-                               One: []int64{1, 2, 3},
-                               Two: [][]string{{"a", "b"}, {"c", "d"}},
+                               One:   []int64{1, 2, 3},
+                               Two:   [][]string{{"a", "b"}, {"c", "d"}},
+                               Three: []string{"hello", "中国"},
                        }
                )

diff --git a/contrib/drivers/pgsql/testdata/issues/issue3632.sql b/contrib/drivers/pgsql/testdata/issues/issue3632.sql
index 94897942a..7738d74a5 100644
--- a/contrib/drivers/pgsql/testdata/issues/issue3632.sql
+++ b/contrib/drivers/pgsql/testdata/issues/issue3632.sql
@@ -1,4 +1,5 @@
 CREATE TABLE "public"."%s" (
   "one" int8[] NOT NULL,
-  "two" text[][] NOT NULL
+  "two" text[][] NOT NULL,
+  "three" json not null
 );

What did you see happen?

=== RUN   Test_Issue3632
INSERT INTO "t_issue3632_1719807582328800552"("one","two","three") VALUES('{1,2,3}','{{"a","b"},{"c","d"}}','{"hello","中国"}') : pq: invalid input syntax for type json
1. INSERT INTO "t_issue3632_1719807582328800552"("one","two","three") VALUES('{1,2,3}','{{"a","b"},{"c","d"}}','{"hello","中国"}')
   1).  github.com/gogf/gf/v2/database/gdb.(*Core).DoCommit
        /opt/repos/go/gf/database/gdb/gdb_core_underlying.go:282
   2).  github.com/gogf/gf/v2/database/gdb.(*Core).DoExec
        /opt/repos/go/gf/database/gdb/gdb_core_underlying.go:139
   3).  github.com/gogf/gf/contrib/drivers/pgsql/v2.(*Driver).DoExec
        /opt/repos/go/gf/contrib/drivers/pgsql/pgsql_do_exec.go:62
   4).  github.com/gogf/gf/v2/database/gdb.(*Core).DoInsert
        /opt/repos/go/gf/database/gdb/gdb_core.go:521
   5).  github.com/gogf/gf/contrib/drivers/pgsql/v2.(*Driver).DoInsert
        /opt/repos/go/gf/contrib/drivers/pgsql/pgsql_do_insert.go:45
   6).  github.com/gogf/gf/v2/database/gdb.(*DriverWrapperDB).DoInsert
        /opt/repos/go/gf/database/gdb/gdb_driver_wrapper_db.go:120
   7).  github.com/gogf/gf/v2/database/gdb.(*HookInsertInput).Next
        /opt/repos/go/gf/database/gdb/gdb_model_hook.go:175
   8).  github.com/gogf/gf/v2/database/gdb.(*Model).doInsertWithOption
        /opt/repos/go/gf/database/gdb/gdb_model_insert.go:333
   9).  github.com/gogf/gf/v2/database/gdb.(*Model).Insert
        /opt/repos/go/gf/database/gdb/gdb_model_insert.go:200
   10). command-line-arguments_test.Test_Issue3632.func1
        /opt/repos/go/gf/contrib/drivers/pgsql/pgsql_z_unit_issue_test.go:104
   11). github.com/gogf/gf/v2/test/gtest.C
        /opt/repos/go/gf/test/gtest/gtest_util.go:36
   12). command-line-arguments_test.Test_Issue3632
        /opt/repos/go/gf/contrib/drivers/pgsql/pgsql_z_unit_issue_test.go:94
2. pq: invalid input syntax for type json

What did you expect to see?

PASS: Test_Issue3632

@tiglog tiglog added the bug It is confirmed a bug, but don't worry, we'll handle it. label Jul 1, 2024
@Issues-translate-bot Issues-translate-bot changed the title contrib/drivers/pgsql: write error with json field contrib/drivers/pgsql: write error with json field Jul 1, 2024
@tianyixueshi
Copy link

same to me . has fixed?

houseme added a commit that referenced this issue Sep 12, 2024
…hub.com:gogf/gf into feature/action-1.23

* 'feature/action-1.23' of github.com:gogf/gf:
  feat: version v2.7.3 (#3763)
  perf(util/gconv):  add cache logic to enhance performance (#3673)
  fix(contrib/drivers/pgsql): fix insert error when data struct field has nil in PgSQL (#3679)
  fix(util/gconv): #3731 map type name mismatch in switch case statement (#3732)
  fix(contrib/drivers/pgsql): #3671 fix invalid pgsql insert json type (#3742)
  refactor(nacos-registry): use official nacos sdk instead of the third-party nacos sdk (#3745)

* 'feature/action-1.23' of github.com:gogf/gf:
  feat: version v2.7.3 (#3763)
  perf(util/gconv):  add cache logic to enhance performance (#3673)
  fix(contrib/drivers/pgsql): fix insert error when data struct field has nil in PgSQL (#3679)
  fix(util/gconv): #3731 map type name mismatch in switch case statement (#3732)
  fix(contrib/drivers/pgsql): #3671 fix invalid pgsql insert json type (#3742)
  refactor(nacos-registry): use official nacos sdk instead of the third-party nacos sdk (#3745)
@gqcn gqcn added the done This issue is done, which may be release in next version. label Sep 24, 2024
@gqcn
Copy link
Member

gqcn commented Sep 24, 2024

@tiglog @tianyixueshi Hello guys, this issue seems was fixed in #3742 . Please feel free to submit issue if it does not behave as expected.

@gqcn gqcn closed this as completed Sep 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug It is confirmed a bug, but don't worry, we'll handle it. done This issue is done, which may be release in next version.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants