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

Breaking change since v1.24.4: Custom serializer on nil-slices #6306

Open
maja42 opened this issue May 9, 2023 · 4 comments
Open

Breaking change since v1.24.4: Custom serializer on nil-slices #6306

maja42 opened this issue May 9, 2023 · 4 comments
Assignees

Comments

@maja42
Copy link

maja42 commented May 9, 2023

I already reported this at go-gorm/postgres#159 a while ago, but it was ignored until now, probably because it's an issue in gorm itself. Since it's turning more and more into an issue for me, I decided to report it here as well:

go (simplified):

type ArgumentList []interface{}   // custom slice-type

// Never called, if `a` is nil (since v1.24.4):
func (a ArgumentList) Value() (driver.Value, error) {
	js, _ := a.MarshalJSON() // Returns a json-array. Nil-slices return "[]".
	return datatypes.JSON(js).Value()
}

func (a *ArgumentList) Scan(value interface{}) error {
	var js datatypes.JSON
	js.Scan(value)
	return json.Unmarshal(js, a)
}

Before 1.4.6, my serializers converted nil-slices to empty json-arrays ([] string).
Now, they are ignored, nil gets converted into a PostgreSQL null, and my not-null-constraints are triggered.
This prevents me from updating the gorm-dependency.

@github-actions github-actions bot added the type:missing reproduction steps missing reproduction steps label May 9, 2023
@maja42
Copy link
Author

maja42 commented May 9, 2023

The "workaround" for this (to support go get -u ./... in go modules) gets longer with each new gorm version:

in go.mod:

exclude gorm.io/gorm v1.24.4
exclude gorm.io/gorm v1.24.5
exclude gorm.io/gorm v1.24.6
exclude gorm.io/gorm v1.24.7
exclude gorm.io/gorm v1.25.0
exclude gorm.io/gorm v1.25.1

exclude gorm.io/driver/postgres v1.4.6
exclude gorm.io/driver/postgres v1.4.7
exclude gorm.io/driver/postgres v1.4.8
exclude gorm.io/driver/postgres v1.5.0

@github-actions
Copy link

github-actions bot commented May 9, 2023

The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.ioSearch Before Asking

@black-06
Copy link
Contributor

black-06 commented May 11, 2023

This is related to the postgres-driver, see jackc/pgx#1566 for more infomation.

@black-06 black-06 removed the type:missing reproduction steps missing reproduction steps label May 11, 2023
Copy link

github-actions bot commented May 5, 2024

This issue has been automatically marked as stale because it has been open 360 days with no activity. Remove stale label or comment or this will be closed in 180 days

phroggyy added a commit to incident-io/postgres that referenced this issue Aug 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants