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 subtyping in dict service #7115

Open
wants to merge 13 commits into
base: staging
Choose a base branch
from

Conversation

Diamekod0221
Copy link
Contributor

Describe your changes

DictApiHttpService sometimes returns improper subtypes like Long type Dicts for Integer or won't return proper types like Number type dict for Long.

Issue is caused by bugs in lang3 lib used in CanBeSubclassDeterminer - the lib would sometimes return incorrect false, and our faulty logic in TypeConversionHandler - the code would return true even if no conversion was possible.

Fixed by adding a double check in SubclassDeterminer and fixing the logic in ConversionHandler.

Checklist before merge

  • Related issue ID is placed at the beginning of PR title in [brackets] (can be GH issue or Nu Jira issue)
  • Code is cleaned from temporary changes and commented out lines
  • Parts of the code that are not easy to understand are documented in the code
  • Changes are covered by automated tests
  • Showcase in dev-application.conf added to demonstrate the feature
  • Documentation added or updated
  • Added entry in Changelog.md describing the change from the perspective of a public distribution user
  • Added MigrationGuide.md entry in the appropriate subcategory if introducing a breaking change
  • Verify that PR will be squashed during merge

@Diamekod0221 Diamekod0221 marked this pull request as ready for review October 30, 2024 15:21
@github-actions github-actions bot added client client main fe ui labels Oct 30, 2024
@Diamekod0221 Diamekod0221 force-pushed the fix_subtyping_in_DictService branch 2 times, most recently from 81e1d11 to 05da3cb Compare October 31, 2024 16:25
}

boxedSuperclassCandidate match {
case candidate if isFloating(candidate) =>
Copy link
Member

Choose a reason for hiding this comment

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

Treating specially implicit conversion for floats is not a way to go, we should have option to check can be subclass without conversion in general

Copy link
Member

Choose a reason for hiding this comment

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

To clarify: we already treat floats specially, the condition here is not changed: if is replaced with pattern matching, the condition is extracted to separate def above.

The only change here is in if isDecimalNumber section:

ConversionFromClassesForDecimals.exists(ClassUtils.isAssignable(boxedGivenClass, _, true))

that checks boxedGivenClass with all possible supertypes (I guess...)
replaced with

CanBeSubclassDeterminer.isAssignable(boxedGivenClass, candidate)

that checks boxedGivenClass with exact given supertype. Aaaand that possibly collides with the java.math.BigDecimal is quite often returned as a wrapper for all kind of numbers.

Copy link
Contributor Author

@Diamekod0221 Diamekod0221 Nov 6, 2024

Choose a reason for hiding this comment

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

Yeah, apart from this isAssignable(boxedGivenClass,...) the logic is exactly the same. To clarify, I think the current staging logic is buggy. It only checks whether a givenType CAN be converted, not if the conversion is to the givenSuperclass. Apart from that I've only included a fallback in case lang3 throws a false false, because the lib gives errors when it comes to decimal java types. In general the program execution flow is the same as intended before.

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 have moved this logic to a separate method and restored the previous logic in the handleNumberConversions method

object CanBeSubclassDeterminer extends CanBeSubclassDeterminer {

// we use explicit autoboxing = true flag, as ClassUtils in commons-lang3:3.3 (used in Flink) cannot handle JDK 11...
def isAssignable(from: Class[_], to: Class[_]): Boolean = {
Copy link
Member

Choose a reason for hiding this comment

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

Please add a test showing when lang3 solution works wrong

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added in CanBeSubclassDeterminerSpec

@@ -135,7 +137,11 @@ trait CanBeSubclassDeterminer {
(),
f"${givenClass.display} and ${superclassCandidate.display} are not the same"
) orElse
isAssignable(givenClass.klass, superclassCandidate.klass)
condNel(
isAssignable(givenClass.klass, superclassCandidate.klass),
Copy link
Member

Choose a reason for hiding this comment

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

Please use CanBeSubclassDeterminer.isAssignable to show that it is our class

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, changed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
client client main fe ui
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants