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

Write two tests that catch a possible bug with SQLite + batchInsert #2116

Closed

Conversation

bystam
Copy link
Contributor

@bystam bystam commented Jun 7, 2024

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 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 - creating a ClassCastException

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)
Copy link
Contributor Author

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)
Copy link
Contributor Author

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

Copy link
Contributor Author

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

Copy link
Collaborator

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.

@bog-walk
Copy link
Member

bog-walk commented Jul 2, 2024

Fixed by PR #2119

@bog-walk bog-walk closed this Jul 2, 2024
@bystam bystam deleted the fix/sqlite-batch-insert-custom-id branch August 12, 2024 10:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants