Skip to content

Conversation

@Eric-Guo
Copy link
Contributor

@Eric-Guo Eric-Guo commented Sep 3, 2025

GPT 5 prompt

I guess due to chinese_name is utf8 input cause above error, can you propose a fix in sponge framework?

example payload

## Get a users by custom condition
# Returns a single users that matches the specified filter conditions.
curl -X "POST" "/api/v1/users/condition" \
     -H 'Accept: *' \
     -H 'Authorization: Bearer' \
     -H 'Content-Type: application/json; charset=utf-8' \
     -d $'{
  "columns": [
    {
      "name": "chinese_name",
      "exp": "like",
      "value": "过%"
    }
  ]
}'

error log

2025-09-03 09:00:54.318	INFO	middleware/logging.go:230	>>>>	{"code": 200, "method": "POST", "url": "/api/v1/users/condition", "time_us": 4108, "size": 1362, "body": "{\"code\":0,\"msg\":\"ok\",\"data\":{\"users\":{\"id\":1,\"email\":\"[email protected]\",\"encryptedPassword\":\"$2a$11$pc3izhrvG9kYisahCXTavuaOWKafPEUsXpeAXCUDkgUADao7lIZpi\",\"resetPasswordToken\":\"\",\"resetPasswordSentAt\":null,\"rememberCreatedAt\":\"2025-04-15T07:20:07+08:00\",\"signInCount\":17845,\"currentS ...... ", "request_id": "K1KyxAQ43T"}
2025-09-03 09:01:11.201	INFO	middleware/logging.go:199	<<<<	{"method": "POST", "url": "/api/v1/users/condition", "size": 68, "body": "{\"columns\":[{\"name\":\"chinese_name\",\"exp\":\"like\",\"value\":\"\\u8fc7%\"}]}", "request_id": "Erq8Ap6sdv"}
2025-09-03 09:01:11.201	WARN	glog/glog.go:94	Gorm msg	{"error": "Error 3988 (HY000): Conversion from collation utf8mb3_general_ci into utf8mb4_0900_ai_ci impossible for parameter", "sql": "SELECT * FROM `users` WHERE chinese_name LIKE 'è\ufffd\ufffd%' ORDER BY `users`.`id` LIMIT 1", "rows": 0, "ms": 0.473583, "file_line": "dao/users.go:339", "request_id": "Erq8Ap6sdv"}
2025-09-03 09:01:11.201	ERROR	handler/users.go:307	GetByCondition error	{"error": "Error 3988 (HY000): Conversion from collation utf8mb3_general_ci into utf8mb4_0900_ai_ci impossible for parameter", "form": {"columns":[{"name":"chinese_name","exp":"like","value":"过%","logic":""}]}, "request_id": "Erq8Ap6sdv"}
test-user-server/internal/handler.(*usersHandler).GetByCondition
	/Users/guochunzhong/git/user_server-web-http/internal/handler/users.go:307
github.com/gin-gonic/gin.(*Context).Next
	/Users/guochunzhong/go/pkg/mod/github.com/gin-gonic/[email protected]/context.go:185
github.com/go-dev-frame/sponge/pkg/gin/middleware/metrics.Metrics.func1
	/Users/guochunzhong/git/oss/sponge/pkg/gin/middleware/metrics/metrics.go:121
github.com/gin-gonic/gin.(*Context).Next
	/Users/guochunzhong/go/pkg/mod/github.com/gin-gonic/[email protected]/context.go:185
github.com/go-dev-frame/sponge/pkg/gin/middleware.Logging.func1
	/Users/guochunzhong/git/oss/sponge/pkg/gin/middleware/logging.go:214
github.com/gin-gonic/gin.(*Context).Next
	/Users/guochunzhong/go/pkg/mod/github.com/gin-gonic/[email protected]/context.go:185
github.com/go-dev-frame/sponge/pkg/gin/middleware.RequestID.func1
	/Users/guochunzhong/git/oss/sponge/pkg/gin/middleware/requstid.go:102
github.com/gin-gonic/gin.(*Context).Next
	/Users/guochunzhong/go/pkg/mod/github.com/gin-gonic/[email protected]/context.go:185
github.com/gin-gonic/gin.CustomRecoveryWithWriter.func1
	/Users/guochunzhong/go/pkg/mod/github.com/gin-gonic/[email protected]/recovery.go:102
github.com/gin-gonic/gin.(*Context).Next
	/Users/guochunzhong/go/pkg/mod/github.com/gin-gonic/[email protected]/context.go:185
github.com/gin-gonic/gin.(*Engine).handleHTTPRequest
	/Users/guochunzhong/go/pkg/mod/github.com/gin-gonic/[email protected]/gin.go:644
github.com/gin-gonic/gin.(*Engine).ServeHTTP
	/Users/guochunzhong/go/pkg/mod/github.com/gin-gonic/[email protected]/gin.go:600
net/http.serverHandler.ServeHTTP
	/opt/homebrew/Cellar/go/1.24.6/libexec/src/net/http/server.go:3301
net/http.(*conn).serve
	/opt/homebrew/Cellar/go/1.24.6/libexec/src/net/http/server.go:2102
2025-09-03 09:01:11.202	ERROR	middleware/logging.go:228	>>>>	{"code": 500, "method": "POST", "url": "/api/v1/users/condition", "time_us": 982, "size": 53, "body": "{\"code\":500,\"msg\":\"Internal Server Error\",\"data\":{}}", "request_id": "Erq8Ap6sdv"}

…ese payload like:

{
  "columns": [
    {
      "name": "chinese_name",
      "exp": "like",
      "value": "过%"
    }
  ]
}
@Eric-Guo Eric-Guo force-pushed the condition_like_in_chinese branch from cde5e14 to 4b8ed64 Compare September 4, 2025 03:38
@zhufuyi zhufuyi merged commit e494163 into go-dev-frame:main Sep 4, 2025
3 checks passed
@Eric-Guo Eric-Guo deleted the condition_like_in_chinese branch September 4, 2025 05:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants