-
-
Notifications
You must be signed in to change notification settings - Fork 235
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
Error default NullZero #664
Comments
example
waiting
waiting The problem appeared after fixing issue 512 |
I just noticed I had the same problem when migrating an application from go-pg/pg to bun. Thanks @dlarin for reporting this! To clarify the issue: it is currently impossible to update a field to the zero value if it is declared with a default value (should we update the title of the issue to clarify?). Note that this is not an issue when inserting an item, since a zero value would be translated either to Elaborating on your example, the following: item := Item{
Count: 5,
Url: "",
}
_, err = db.NewInsert().Model(&item).Exec(ctx) would generate: -- Using PostgreSQL, where DEFAULT placeholder is supported:
INSERT INTO "item" ("nomenclature_guid", "count", "url") VALUES (NULL, 5, DEFAULT);
-- Using a database where DEFAULT placeholder is not supported, e.q. sqlite:
INSERT INTO "item" ("nomenclature_guid", "count", "url") VALUES (NULL, 5 , ''); In both cases, the Then, as @dlarin showed previously, an update to the zero value is impossible as it is translated to NULL (see query_update.go#L313 which calls schema/field.go#L96-L98), since the item.Url = ""
_, err = db.NewUpdate().Model(&item).Column("url").WherePK().Exec(context.Background()) UPDATE "item" SET "url" = NULL WHERE ("item"."id" = 1) This is unexpected and seems like a bug. A short-term workaround would be to use EDIT (2024-11-14): the workaround is no longer needed with all Bun versions >= 1.1.17 (see comment) |
same to me. |
bun issue: uptrace/bun#664
Also having this issue. Had to remove all default values, which is obviously highly problematic. Is it specific to Postgres? |
Any update on this? |
same here, had to remove "default" value from the model field |
This issue has been automatically marked as stale because it has not had activity in the last 30 days. If there is no update within the next 7 days, this issue will be closed. |
Let's keep it open, unless someone can confirm it was fixed. |
In the latest version(v1.2.5), the |
@j2gg0s Thanks for checking this 🙏 Indeed, Bun version 1.1.17 shipped with a fix from #937 (here) ensuring that the I've tested this change in one of my applications that would be affected by this issue, and I can confirm it is fixed if using Bun 1.1.17+. This issue can be closed as resolved! |
when inserting or updating, the value is equal to the default value, then it is replaced with null
tag.option "default" set NullZero = true. Because of this, we get that value null
https://github.com/uptrace/bun/blob/master/schema/table.go#L380
https://github.com/uptrace/bun/blob/master/schema/field.go#L96
The text was updated successfully, but these errors were encountered: