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
EXPOSED-372 UpsertStatement.resultedValues contains incorrect value #2075
EXPOSED-372 UpsertStatement.resultedValues contains incorrect value #2075
Conversation
It looks like it's the wrong way to fix it, because other tests fail with |
It works now but particularly for Postgres. Using upsert command with other DBs will cause the same problem of returning wrong ID. It may confuse users. |
|
||
// At present, only Postgres returns the correct UUID directly from the result set. | ||
// For other databases incorrect ID is returned from the 'upsert' command. | ||
withTables(excludeSettings = TestDB.entries - listOf(TestDB.POSTGRESQL, TestDB.POSTGRESQLNG), tester) { testDb -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the future, there are some available sets for common TestDB
collections in its companion object, if you ever need them.
From my understanding, PostgreSQL will be the only database that returns a result set populated with inserted/updated values that are not auto-incrementing. It might be good to investigate later if we can instead return a null |
@bog-walk, if we're returning invalid UUID for some DBs it should be fixed before merging |
Here is the fix for the issue EXPOSED-372
The problem is that
upsert()
command returns a wrong id in the case ofUUIDTable
.The key reason for that difference I found is that for that table the
uuid(columnName).autoGenerate().entityId()
column is used, but insideInsertStatement
there is a conditioncol.columnType.isAutoInc || value is NextVal<*>
for overwriting the value fromarguments
.I added
col.defaultValueFun != null
to the condition to avoid hard overwriting of the value from the result set. It fixes the problem from the issue.But I feel that something wrong happens there, because it's weird to me that we need to rewrite values from result stet at all. I tried to replace the whole block:
with the statement
map.getOrPut(col) { value }
assuming that we take values from arguments only if it's not in the result set.But after such change, some other tests start to fail (particularly for SQLite), because of the line above:
The value returned from
rs.getObject(1)
is not actual id, but something different. The testInsertTests::testInsertWithPredefinedId()
fails onassertEquals(id1, entityID)
with errorFailed on SQLITE expected:<1> but was:<id1>
. What means thatrs.getObject(1)
returned1
instead ofid1
(actual value in DB at this moment isid1
).