-
Notifications
You must be signed in to change notification settings - Fork 694
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
Write two tests that catch a possible bug with SQLite + batchInsert #2116
Conversation
Two errors show up: 1. A customly declared ID column is not set to the `id` property on DAO `new {}` 2. The ResultRow from a `batchInsert` fails to unwrap data on 2 ways: - if you check the `id` first, it fails because it becomes 1 instead of "batman" as the test expected - if you check `username` first, it fails later on `id` because the ResultRow caches the internal lookup, but the cache doesn't make a distinction between the return value String and EntityID<String> - creating a ClassCastException
val result1 = User.batchInsert(listOf("batman")) { username -> | ||
this[User.username] = username | ||
}.single() | ||
assertEquals("batman", result1[User.id].value) |
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.
Fails, because result1[User.id].value
is 1
on SQLite
this[User.username] = username | ||
}.single() | ||
assertEquals("superman", result2[User.username]) | ||
assertEquals("superman", result2[User.id].value) |
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.
Fails, because result2[User.username]
caches the return value as a String
, meaning result2[User.id].value
produces a ClassCastException
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.
Arguably should be a separate PR, because this is not related to SQLite specifically - this fails on any database
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.
Created another https://youtrack.jetbrains.com/issue/EXPOSED-409/Custom-primary-key.-Access-to-the-primary-key-fails-with-ClassCastException issue for the second problem. It's clear why it happens, I'll try to fix it a bit later.
Fixed by PR #2119 |
YouTrack: https://youtrack.jetbrains.com/issue/EXPOSED-405/SQLite-bugs-Table-with-custom-ID-behaves-weirdly-in-DAO-and-batchInsert
Two errors show up:
1. A customly declared ID column is not set to the
id
property on DAOnew {}
2. The ResultRow from a
batchInsert
fails to unwrap data on 2 ways:- if you check the
id
first, it fails because it becomes 1 instead of "batman" as the test expected- if you check
username
first, it fails later onid
because the ResultRow caches the internal lookup, but the cache doesn't make a distinctionbetween the return value String and EntityID - creating a ClassCastException