fix: nil scope values being excluded from scope filtering#476
fix: nil scope values being excluded from scope filtering#476seuros merged 2 commits intoClosureTree:masterfrom
Conversation
There was a problem hiding this comment.
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.
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 |
|
Today, I need to test it from master. Also test with advisory lock gem. Can you do the same in your app ? We cannot ship untested code as the locking is pretty hard to dwbug. |
3d71ad0 to
f9fc186
Compare
f9fc186 to
a05be1a
Compare
Hi @seuros I ran a sanity check on my app after the recent changes, and everything looked good. Since our app uses PostgreSQL, the testing was done against that database. |
|
Same here. I will prepare a release. |
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.