Fix deprecation warning and correctness bug when using arel_extensions >= 2.2#1679
Open
javieromar7 wants to merge 1 commit into
Conversation
…ated_key ArelExtensions >= 2.2 overrides on Arel attributes to build SQL predicate nodes (Arel::Nodes::Equality) instead of returning a boolean. This caused two problems in extract_correlated_key: 1. A DEPRECATION WARNING on every query involving correlated joins. 2. A silent correctness bug: the comparison always returned truthy (an Arel node is never nil/false), so join_root.right was always returned regardless of whether join_root.left was actually the PK. Replace with , which performs value-based comparison on Arel::Attributes::Attribute objects (comparing name and relation) without going through the ArelExtensions override.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When
arel_extensions >= 2.2is present,extract_correlated_keytriggers a deprecation warning on every query involving correlated joins:Beyond the warning, there is a silent correctness bug:
ArelExtensions >= 2.2overrides==on Arel attributes to return anArel::Nodes::EqualitySQL predicate node — not a boolean. This means theif join_root.left == pkcheck is always truthy (an Arel node is nevernil/false), sojoin_root.rightis returned unconditionally, regardless of whetherjoin_root.leftis actually the primary key.Root cause
Fix
Replace
==witheql?for the primary key identity check.Arel::Attributes::Attribute#eql?performs value-based comparison (name + relation) without going through the ArelExtensions override.Verification