Skip to content

fix: EXPOSED-983 Support reading JSONB columns outside transaction by using ResultRow.database instead of current transaction when checking dialect#2748

Open
bystam wants to merge 1 commit intoJetBrains:mainfrom
bystam:fix/avoid-crash-reading-jsonb-outside-transaction
Open

fix: EXPOSED-983 Support reading JSONB columns outside transaction by using ResultRow.database instead of current transaction when checking dialect#2748
bystam wants to merge 1 commit intoJetBrains:mainfrom
bystam:fix/avoid-crash-reading-jsonb-outside-transaction

Conversation

@bystam
Copy link
Contributor

@bystam bystam commented Mar 3, 2026

Description

A recent change in how JSONB is treated in SQLite has caused an unexpected behavior when reading JSONB columns outside the transaction.

For us it's a common pattern to return entities from a transaction and then perform read-only operations on them (such as writing to some kind of JSON endpoint output), and when bumping to 1.0.0 we started seeing crashes, because the change linked upstairs pokes at currentDialect when parsing the json column.

By checking the stack trace, I noticed that the specific codepath that crashes has access to the database use to retrieve the ResultRow, and therefore we can avoid the crash by reading the dialect from there instead of from the thread-local.


Type of Change

Please mark the relevant options with an "X":

  • Bug fix
  • New feature
  • Documentation update

Updates/remove existing public API methods:

  • Is breaking change

Affected databases:
Note: I'm not sure if this change can be considered to affect any of these databases specifically

  • MariaDB
  • Mysql5
  • Mysql8
  • Oracle
  • Postgres
  • SqlServer
  • H2
  • SQLite

Checklist

  • Unit tests are in place
  • The build is green (including the Detekt check)
  • All public methods affected by my PR has up to date API docs
  • Documentation for my change is up to date

Related Issues

https://youtrack.jetbrains.com/issue/EXPOSED-983/JSONB-columns-cannot-be-read-outside-of-transaction

@bystam bystam force-pushed the fix/avoid-crash-reading-jsonb-outside-transaction branch from 27e6b70 to 049a8e7 Compare March 3, 2026 09:10
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I could tell, currentDialect is SQLiteDialect was double-checked both here and inside needsBinaryFormatCast, but only one of them should be required?

At least from what I could tell from the callers of both functions

@bystam bystam force-pushed the fix/avoid-crash-reading-jsonb-outside-transaction branch from 049a8e7 to 70700fa Compare March 3, 2026 09:12
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the fix that actually avoids the crash - by using database?.dialect and avoiding checking the current transaction

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't find a way to inject the "current database" as easily from from 2 other places where isJsonBColumnForCasting is called:

  • Alias.kt
  • Table.kt

Maybe it's OK to have them simply use the thread-local?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This last line crashes without the fix upstairs

@bystam bystam force-pushed the fix/avoid-crash-reading-jsonb-outside-transaction branch from 70700fa to 1a8801d Compare March 3, 2026 09:29
… using ResultRow.database instead of current transaction when checking dialect
@bystam bystam force-pushed the fix/avoid-crash-reading-jsonb-outside-transaction branch from 1a8801d to 8b0597d Compare March 3, 2026 10:01
@bog-walk bog-walk self-assigned this Mar 6, 2026
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.

2 participants