-
Notifications
You must be signed in to change notification settings - Fork 249
Fix nil scope values being excluded from scope filtering #476
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
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes a bug where nil scope values were incorrectly excluded from scope filtering, causing records with nil scope values to bypass scope restrictions during operations like reordering.
Changes:
- Removed
nilvalue exclusion checks inscope_values_from_instancemethod - Added comprehensive tests for
nilscope values in both single and multi-column scope configurations - Verified ordering behavior with
nilscope values
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| lib/closure_tree/support.rb | Removed unless value.nil? checks to allow nil values in scope hash |
| test/closure_tree/scope_test.rb | Added tests for scope_values_from_instance with nil values and ordering with nil scopes |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
seuros
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change is 👍🏼 , however the test need to test in the 3 database types.
Scoped Item is connected to PG. check the test/dummy app for the others models.
We just need to assert that it won't blow up with another engine.
Hi @seuros , Thanks for reviewing. Added separate tests for each DB types - 3d71ad0 |
Overview
This PR fixes a bug where
nilscope values were being skipped inscope_values_from_instance, resulting in no scope filtering being applied instead of the intendedIS NULLSQL condition.Motivation
When using the scope option with columns that have
nilvalues, thescope_values_from_instancemethod was incorrectly skipping those values due to unlessvalue.nil?checks. This caused:nilscope values to have no scope filtering applied (empty hash{}).build_scope_where_clausenever receivingnilvalues, making itsIS NULLhandling unreachable.nilscope values.Behavior Change
nilscope values now generate proper SQL filtering: When a scope column hasnilvalue, the query now includesWHERE column IS NULLinstead of having no scope filter at all.nilscopes: When calling_ct_reorder_siblingsor_ct_reorder_childrenon a record withnilscope values, only records with matching
nilscope values are reordered together. Previously, an empty scope hash caused all records (regardless of scope) to be reordered.nilscoped records are properly isolated: Records withnilscope values are now treated as their own distinct scope group, separate from records with nonnilscope values.Code Changes
lib/closure_tree/support.rbunless value.nil?check fromSymbolscope type (line 241)unless value.nil?check fromArrayscope type (line 246)Before:
After:
test/closure_tree/scope_test.rbtest_scope_values_from_instance_with_nil_value_symbol_scopenilvalues are included for Symbol scopetest_scope_values_from_instance_with_nil_value_array_scopenilvalues are included for Array scopetest_ordering_with_nil_scope_values_symbol_scopetest_ordering_with_nil_scope_values_array_scopeBackward Compatibility
This is a bug fix that makes the scope option work as intended. Existing code using non
nilscope values is unaffected. Code relying on the buggy behavior (nilscope = no filtering) will see different results.