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 Durations Convert to 0 #1196

Closed
ccjernigan opened this issue Mar 31, 2021 · 0 comments
Closed

Null Durations Convert to 0 #1196

ccjernigan opened this issue Mar 31, 2021 · 0 comments

Comments

@ccjernigan
Copy link

ccjernigan commented Mar 31, 2021

STEPS TO REPRODUCE

  1. Configure a table with a duration column type that is nullable
  2. Write a row with null into that duration column
  3. Read that row back

In code:

Table definition

object SampleDurationTable : UUIDTable("duration_example_table") {
    val elapsedDuration = duration("elapsed_duration").nullable()
    val elapsedDouble = double("elapsed_double").nullable()

    fun insert(duration: Duration?) = insertAndGetId {
        it[elapsedDuration] = duration?.toJavaDuration()
        it[elapsedDouble] = duration?.inSeconds
    }
}

Test case

    @Test
    fun `null duration`() {
         // Sets up in-memory SQLite database
        @Suppress("UNUSED_VARIABLE") val db = Db(type = Db.Type.Memory)

        transaction {
            SampleDurationTable.insert(null)

            assertEquals(1, SampleDurationTable.selectAll().count())

            val row = SampleDurationTable.selectAll().first()
            val doubleItem = row.getOrNull(SampleDurationTable.elapsedDouble)
            val durationItem = row.getOrNull(SampleDurationTable.elapsedDuration)?.toKotlinDuration()

            assertNull(doubleItem, "Got $doubleItem instead of null double") // pass
            assertNull(durationItem, "Got $durationItem instead of null duration") // fail
        }
    }

RESULTS
Actual:
Duration is converted to 0

Expected:
Duration should continue to be null

NOTES
I tested this with an on-disk database, and found that null is being written when I inspect the database directly. So it appears the bug might be occurring when the data is being read back

WORKAROUND
Manually convert Duration type into another representation, such as Double.

Tapac added a commit that referenced this issue Apr 4, 2021
Duration added to tests
Tapac added a commit that referenced this issue Apr 4, 2021
@Tapac Tapac closed this as completed Apr 5, 2021
SchweinchenFuntik pushed a commit to SchweinchenFuntik/Exposed that referenced this issue Oct 23, 2021
SchweinchenFuntik pushed a commit to SchweinchenFuntik/Exposed that referenced this issue Oct 23, 2021
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

No branches or pull requests

2 participants