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

Deleting entity after it is created does not delete it from cache #1175

Closed
kiliangrashoff opened this issue Feb 18, 2021 · 0 comments
Closed

Comments

@kiliangrashoff
Copy link

kiliangrashoff commented Feb 18, 2021

If an entity is deleted after creation, but before the EntityCache is flushed, it is not deleted from the cache and will be returned by findById(id: ID) in the same transaction block. The behaviour I would expect is that the entity is deleted from the cache, and that findById(id: ID) would return null. Flushing the cache before delete, or opening a new transaction block before deleting the entity fixes the issue.

Reproduction case:

import org.jetbrains.exposed.dao.UUIDEntity
import org.jetbrains.exposed.dao.UUIDEntityClass
import org.jetbrains.exposed.dao.id.EntityID
import org.jetbrains.exposed.dao.id.UUIDTable
import org.jetbrains.exposed.sql.Database
import org.jetbrains.exposed.sql.SchemaUtils
import org.jetbrains.exposed.sql.transactions.transaction
import java.util.*

object Tests : UUIDTable("tests")

class Test(id: EntityID<UUID>) : UUIDEntity(id) {
	companion object : UUIDEntityClass<Test>(Tests)
}

fun main() {
	Database.connect(
		url = "db url",
		driver = "db driver",,
		user = "db user",
		password = "db password",
	)
	transaction {
		SchemaUtils.create(Tests)
		val testEntity = Test.new { }
		val testEntityId = testEntity.id.value
		testEntity.delete()
		println(Test.findById(testEntityId) == null) // actual: false, expected: true
		SchemaUtils.drop(Tests)
	}
}

Affected versions: 0.22.1 and 0.29.1 (others not tested)
Database: PostgreSQL 42.2.6

@kiliangrashoff kiliangrashoff changed the title Deleting entity after it is created does not delete it from transaction cache Deleting entity after it is created does not delete it from cache Feb 18, 2021
@Tapac Tapac closed this as completed Apr 1, 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