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

fix: EXPOSED-472 Alias IdTable fails with isNull and eq ops #2189

Merged
merged 3 commits into from
Aug 7, 2024

Conversation

bog-walk
Copy link
Member

@bog-walk bog-walk commented Aug 5, 2024

Description

Summary of the change: Using any aliased IdTable with isNull() or eq() no longer throws a class cast exception.

Detailed description:

  • Why:
    The introduction of CompositeIdTable (PR feat: EXPOSED-77 Support entity class for table with composite primary key #1987 ), and internal functions mapIdComparison and mapIdOperator, led to a regression. When any IdTable is aliased and used with the associated comparison operators, eq and isNull (and negative variants), the following is thrown: org.jetbrains.exposed.sql.Alias cannot be cast to org.jetbrains.exposed.dao.id.IdTable

  • What:
    The Alias class now has its own override for these internal functions, so that the aliased idColumns of the delegate are used.

  • How:

    • Both mapIdComparison and mapIdOperator have been moved a level down to Table, so that they can be overridden by Alias as well, which is a subclass too.
    • Alias.get() operator has also been fixed to allow CompositeIdTable to be aliased and still access the delegate id column properly.

Type of Change

Please mark the relevant options with an "X":

  • Bug fix

Affected databases:

  • All

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

Related Issues

EXPOSED-472

Copy link
Member

@e5l e5l left a comment

Choose a reason for hiding this comment

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

lgtm

toCompare: Any?,
operator: (Column<*>, Expression<*>) -> Op<Boolean>,
): Op<Boolean> {
return when (delegate) {
Copy link
Member

Choose a reason for hiding this comment

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

I would use = instead of return here and eliminate inner returns to simplify reading

@Suppress("UNCHECKED_CAST")
override fun mapIdComparison(
toCompare: Any?,
operator: (Column<*>, Expression<*>) -> Op<Boolean>,
Copy link
Member

Choose a reason for hiding this comment

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

operator is a keyword (soft), please consider using other name

The introduction of `CompositeIdTable`, and functions like `mapIdComparison` an>
`mapIdOperator`, led to a regression. When any `IdTable` is aliased and used wi>
the affected comparison operators, `eq` and `isNull` (and negative variants),
the following is thrown:
org.jetbrains.exposed.sql.Alias cannot be cast to org.jetbrains.exposed.dao.id.>

The aliased `idColumns` of the `Alias` delegate need to be used in these functi>
so these internal functions have been brought a level down, into the `Table` cl>
so they can be overridden in `Alias` as well.

`Alias.get()` operator has also been fixed to allow `CompositeIdTable` to be al>
and still access the delegate `id` column properly.
- Change Alias override internal return to function = operator
- Rename both internal function parameters to booleanOperator instead of operator
- Rebase from main
- Remove unecessary cast
@bog-walk bog-walk merged commit ac67c44 into main Aug 7, 2024
5 checks passed
@bog-walk bog-walk deleted the bog-walk/fix-alias-isnull branch August 7, 2024 18:41
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