question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Bug] Regression in 0.22.1, createMissingTablesAndColumns fails

See original GitHub issue

The code below works with exposed 0.21.1, but fails with 0.22.1.

package org.user5145.champion.integration

import com.zaxxer.hikari.HikariConfig
import com.zaxxer.hikari.HikariDataSource
import org.jetbrains.exposed.dao.id.IdTable
import org.jetbrains.exposed.sql.*
import org.jetbrains.exposed.sql.transactions.transaction
import kotlin.test.Test

class BugTest {
    fun getDefaultDb(): Database {
        val config = HikariConfig()
        config.jdbcUrl = "jdbc:h2:mem:test;MODE=Postgresql;DB_CLOSE_DELAY=-1;DATABASE_TO_LOWER=TRUE"
        config.username = ""
        config.password = ""
        config.driverClassName = "org.h2.Driver"
        return Database.connect(HikariDataSource(config))
    }

    object Champions : IdTable<String>() {
        override val id get() = username
        val username = varchar("name", 50).entityId()
        val pass = text("pass")
    }

    object ChampionsStats : IdTable<String>("champions_stats") {
        override val id get() = username
        val username = varchar("name", 50).entityId() references Champions.username
        val hp = text("hp")
    }

    @Test
    fun testCreate() {
        transaction(getDefaultDb()) {
            SchemaUtils.createMissingTablesAndColumns(Champions, ChampionsStats)
        }
    }
}

Stacktrace head:

Collection contains no element matching the predicate.
java.util.NoSuchElementException: Collection contains no element matching the predicate.
	at org.jetbrains.exposed.sql.statements.jdbc.JdbcDatabaseMetadataImpl$tableConstraints$$inlined$associateWith$lambda$1.invoke(JdbcDatabaseMetadataImpl.kt:170)
	at org.jetbrains.exposed.sql.statements.jdbc.JdbcDatabaseMetadataImpl$tableConstraints$$inlined$associateWith$lambda$1.invoke(JdbcDatabaseMetadataImpl.kt:13)
	at org.jetbrains.exposed.sql.statements.jdbc.JdbcDatabaseMetadataImplKt.iterate(JdbcDatabaseMetadataImpl.kt:164)
	at org.jetbrains.exposed.sql.statements.jdbc.JdbcDatabaseMetadataImpl.tableConstraints(JdbcDatabaseMetadataImpl.kt:123)

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
MrPowerGamerBRcommented, May 7, 2020

This issue still happens in 0.24.1 if you do this (using PostgreSQL):

  1. Create a table object with a external table reference (Example: var myExternalReference = optReference("my_external_reference", MyExternalTable, onDelete = ReferenceOption.CASCADE).index())
  2. Create the table with SchemaUtils.createMissingTablesAndColumns
  3. Remove the reference from the table in your code
  4. Use SchemaUtils.createMissingTablesAndColumns again
  5. Exposed fails to create the table… even tho it is already created

Then the error happens, this doesn’t happen with 0.17.7 (which was the previous Exposed version I was using before I upgraded)

Not sure if this is intentional because sometimes you don’t want to map everything from your database table to Exposed (in my case sometimes I remove features from my app that I didn’t remove from the database schema yet, in 0.17.7 it worked fine… in 0.24.1 it breaks)

@Tapac should a new issue be created about this issue, or does it fit in here too? The stacktrace is the same as the one in this issue.

Exception in thread "main" java.util.NoSuchElementException: Collection contains no element matching the predicate.
        at org.jetbrains.exposed.sql.statements.jdbc.JdbcDatabaseMetadataImpl$tableConstraints$$inlined$associateWith$lambda$1.invoke(JdbcDatabaseMetadataImpl.kt:213)
        at org.jetbrains.exposed.sql.statements.jdbc.JdbcDatabaseMetadataImpl$tableConstraints$$inlined$associateWith$lambda$1.invoke(JdbcDatabaseMetadataImpl.kt:13)
        at org.jetbrains.exposed.sql.statements.jdbc.JdbcDatabaseMetadataImplKt.iterate(JdbcDatabaseMetadataImpl.kt:206)
        at org.jetbrains.exposed.sql.statements.jdbc.JdbcDatabaseMetadataImpl.tableConstraints(JdbcDatabaseMetadataImpl.kt:170)
        at org.jetbrains.exposed.sql.vendors.VendorDialect$fillConstraintCacheForTables$1.invoke(Default.kt:677)
        at org.jetbrains.exposed.sql.vendors.VendorDialect$fillConstraintCacheForTables$1.invoke(Default.kt:584)
        at org.jetbrains.exposed.sql.statements.jdbc.JdbcConnectionImpl.metadata(JdbcConnectionImpl.kt:51)
        at org.jetbrains.exposed.sql.Database.metadata$exposed_core(Database.kt:29)
        at org.jetbrains.exposed.sql.vendors.VendorDialect.fillConstraintCacheForTables(Default.kt:677)
        at org.jetbrains.exposed.sql.vendors.VendorDialect.columnConstraints(Default.kt:655)
        at org.jetbrains.exposed.sql.SchemaUtils.addMissingColumnsStatements(SchemaUtils.kt:144)
        at org.jetbrains.exposed.sql.SchemaUtils.createMissingTablesAndColumns(SchemaUtils.kt:240)
        at org.jetbrains.exposed.sql.SchemaUtils.createMissingTablesAndColumns$default(SchemaUtils.kt:228)
        at com.mrpowergamerbr.loritta.Loritta$initPostgreSql$1.invoke(Loritta.kt:389)
1reaction
user5145commented, Apr 11, 2020

Works fine in 0.23.1 for me, but I will keep the issue for @baptistecassar

@Tapac changing

varchar("name", 50).entityId() references Champions.username
to
reference("name", Champions)

doesn’t do much. If you still want a sample, here

@baptistecassar I’ve been getting this error in 0.23.1 while using postgres, but it was caused by gradle cache and “Reimport all gradle projects” button helped. image

Thanks for your help @Tapac 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Blue-teaming for Exiv2: three rules of bug fixing for better OSS ...
When you fix a bug, you should add a regression test, which is designed to fail if the same bug is ever reintroduced....
Read more >
Why Understanding Regression Defects Is Crucial - HeadSpin
This quick guide highlights the importance of understanding regression defects and the best practices for preventing regression defects.
Read more >
Five Common Problems With your Regression Testing Strategy
Regression Testing is Not “Sexy”. The Problem. There's no way around it – regression testing involves running the same tests over and over...
Read more >
Reading 11: Debugging - MIT
Reproduce the Bug. Start by finding a small, repeatable test case that produces the failure. If the bug was found by regression testing,...
Read more >
Bug #81088 :: error in regression test for oci_fetch_object ...
Bug #81088, error in regression test for oci_fetch_object() and oci_fetch_array(). Submitted: 2021-05-28 15:15 UTC, Modified: ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found