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

The behavior of Gorm for nil values has changed after v2.5 #271

Open
liaohongxing opened this issue Dec 20, 2024 · 2 comments
Open

The behavior of Gorm for nil values has changed after v2.5 #271

liaohongxing opened this issue Dec 20, 2024 · 2 comments
Labels
Bug Report a reproducible bug or regression

Comments

@liaohongxing
Copy link

Hello,

I encountered an issue with the following code:

type Test struct {
  Field1 carbon.Carbon `json:"field1"`
}

input :=  new(Person)

golang version: v1.23.4

carbon version: v2.5.2

time zone: Asia/Shanghai

I expected to get:

null

But I actually get:

""

从 github.com/golang-module 切换到 github.com/dromara 后,发现跟gorm配合出现问题,当New出一个包含carbon的结构体后,没有给字段赋值时,对nil值处理出现问题 ,之前是正确的 null 值,现在是空字符串,导致插入数据库报错。

@liaohongxing liaohongxing added the Bug Report a reproducible bug or regression label Dec 20, 2024
@liaohongxing liaohongxing changed the title The behavior of Gorm for nil values has changed after The behavior of Gorm for nil values has changed after v2.5 The behavior of Gorm for nil values has changed after v2.5 Dec 20, 2024
@gouguoyin
Copy link
Collaborator

空字符串插入数据库为什么会报错,能贴出代码么

@liaohongxing
Copy link
Author

代码回退了,现成的代码没有 ,pg类型很严格 ,空字符串不能插入timestamp with time zone列,mysql可能可以 , 就是 new 出一个包含carbon的指针, carbon字段不赋值 ,经gorm插入, 现在字段表现是 空字符串 报插入异常 ,之前是null ,插入正常

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Report a reproducible bug or regression
Projects
None yet
Development

No branches or pull requests

2 participants