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

"NULL in non-nullable column" error should include the offending table and column name #1268

Open
vlsi opened this issue Jun 15, 2021 · 0 comments

Comments

@vlsi
Copy link

vlsi commented Jun 15, 2021

exposed-core:0.31.1

java.lang.IllegalStateException: NULL in non-nullable column
	at org.jetbrains.exposed.sql.IColumnType$DefaultImpls.valueToString(ColumnType.kt:48)
	at org.jetbrains.exposed.sql.ColumnType.valueToString(ColumnType.kt:74)
	at org.jetbrains.exposed.sql.QueryBuilder$registerArguments$1.invoke(Expression.kt:69)
	at org.jetbrains.exposed.sql.QueryBuilder.registerArguments(Expression.kt:72)
	at org.jetbrains.exposed.sql.QueryBuilder.registerArgument(Expression.kt:63)
	at org.jetbrains.exposed.sql.QueryBuilder.registerArgument(Expression.kt:58)
	at org.jetbrains.exposed.sql.statements.UpdateStatement.arguments(UpdateStatement.kt:26)
	at org.jetbrains.exposed.sql.statements.Statement.executeIn$exposed_core(Statement.kt:31)
	at org.jetbrains.exposed.sql.Transaction.exec(Transaction.kt:129)
	at org.jetbrains.exposed.sql.Transaction.exec(Transaction.kt:115)
	at org.jetbrains.exposed.sql.statements.Statement.execute(Statement.kt:28)
	at org.jetbrains.exposed.sql.QueriesKt.update(Queries.kt:178)
	at org.jetbrains.exposed.sql.QueriesKt.update$default(Queries.kt:175)

Please add the relevant context information so users could tell what was wrong with the code.

In my case, the error was caused by val refId = reference(...) instead of val refId = optReference(...).
The actual DB model was "optional foreign key", so the proper API should be optReference.

However, the strange thing is reference(..) field accepts nulls, and optReference(..) rejects null in update and insert.

vlsi added a commit to vlsi/Exposed that referenced this issue Jun 19, 2021
* Exception message would include the relevant table and column name
* LiteralOp(...) and QueryParameter(...) would fail if user creates NULL value for non-nullable type
* Single-value QueryBuilder#registerArgument is slightly faster as it no longer creates list

fixes JetBrains#1268
vlsi added a commit to vlsi/Exposed that referenced this issue Jun 19, 2021
* Exception message would include the relevant table and column name
* LiteralOp(...) and QueryParameter(...) would fail if user creates NULL value for non-nullable type
* Single-value QueryBuilder#registerArgument is slightly faster as it no longer creates list

fixes JetBrains#1268
vlsi added a commit to vlsi/Exposed that referenced this issue Jun 19, 2021
* Exception message would include the relevant table and column name
* LiteralOp(...) and QueryParameter(...) would fail if user creates NULL value for non-nullable type
* Single-value QueryBuilder#registerArgument is slightly faster as it no longer creates list

fixes JetBrains#1268
vlsi added a commit to vlsi/Exposed that referenced this issue Jun 19, 2021
* Exception message would include the relevant table and column name
* LiteralOp(...) and QueryParameter(...) would fail if user creates NULL value for non-nullable type
* Single-value QueryBuilder#registerArgument is slightly faster as it no longer creates list

fixes JetBrains#1268
vlsi added a commit to vlsi/Exposed that referenced this issue Jun 19, 2021
* Exception message would include the relevant table and column name
* LiteralOp(...) and QueryParameter(...) would fail if user creates NULL value for non-nullable type
* Single-value QueryBuilder#registerArgument is slightly faster as it no longer creates list

fixes JetBrains#1268
vlsi added a commit to vlsi/Exposed that referenced this issue Jun 19, 2021
* Exception message would include the relevant table and column name
* LiteralOp(...) and QueryParameter(...) would fail if user creates NULL value for non-nullable type
* Single-value QueryBuilder#registerArgument is slightly faster as it no longer creates list

fixes JetBrains#1268
vlsi added a commit to vlsi/Exposed that referenced this issue Jun 19, 2021
* Exception message would include the relevant table and column name
* LiteralOp(...) and QueryParameter(...) would fail if user creates NULL value for non-nullable type
* Single-value QueryBuilder#registerArgument is slightly faster as it no longer creates list

fixes JetBrains#1268
vlsi added a commit to vlsi/Exposed that referenced this issue Jun 19, 2021
* Exception message would include the relevant table and column name
* LiteralOp(...) and QueryParameter(...) would fail if user creates NULL value for non-nullable type
* Single-value QueryBuilder#registerArgument is slightly faster as it no longer creates list

fixes JetBrains#1268
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

2 participants