Skip to content

Conversation

groyoh
Copy link
Contributor

@groyoh groyoh commented Jun 27, 2025

Context

As we use some default scopes on models and/or associations using order, a warning is logged when we call find_each on them.

Description

This PR fixes the warnings by using unscope(:order) before calling find_each. It also changes the config.active_record.error_on_ignored_order to true in the test environment to ensure we raise an error instead of logging.

Example of failed spec:

bundle exec rspec spec/services/charge_filters/create_or_update_batch_service_spec.rb
                                                                                                                                                                                                                                         
  1) ChargeFilters::CreateOrUpdateBatchService when filter params is empty when there are existing filters with cascade_updates set to true and existing filters discards all filters and the related values that are inherited from parent
     Failure/Error: charge.filters.where(id: inherited_filter_ids).find_each { remove_filter(it) }
     
     ArgumentError:
       Scoped order is ignored, use :cursor with :order to configure custom order.
     # ./app/services/charge_filters/create_or_update_batch_service.rb:118:in 'block in ChargeFilters::CreateOrUpdateBatchService#remove_all'
     # ./app/services/charge_filters/create_or_update_batch_service.rb:116:in 'ChargeFilters::CreateOrUpdateBatchService#remove_all'
     # ./app/services/charge_filters/create_or_update_batch_service.rb:23:in 'ChargeFilters::CreateOrUpdateBatchService#call'
     # ./app/services/base_service.rb:243:in 'block in BaseService.call'
     # ./app/services/base_service.rb:237:in 'BaseService.call'
     # ./spec/services/charge_filters/create_or_update_batch_service_spec.rb:6:in 'block (2 levels) in <top (required)>'
     # ./spec/services/charge_filters/create_or_update_batch_service_spec.rb:96:in 'block (6 levels) in <top (required)>'
     # ./spec/services/charge_filters/create_or_update_batch_service_spec.rb:96:in 'block (5 levels) in <top (required)>'
     # ./spec/spec_helper.rb:160:in 'block (3 levels) in <top (required)>'
     # ./spec/spec_helper.rb:159:in 'block (2 levels) in <top (required)>'

                                                                                                                                                                                                                                         
  2) ChargeFilters::CreateOrUpdateBatchService when filter params is empty when there are existing filters with cascade_updates set to true and existing filters does not discard filters and the related values that are defined on child
     Failure/Error: charge.filters.where(id: inherited_filter_ids).find_each { remove_filter(it) }
     
     ArgumentError:
       Scoped order is ignored, use :cursor with :order to configure custom order.
     # ./app/services/charge_filters/create_or_update_batch_service.rb:118:in 'block in ChargeFilters::CreateOrUpdateBatchService#remove_all'
     # ./app/services/charge_filters/create_or_update_batch_service.rb:116:in 'ChargeFilters::CreateOrUpdateBatchService#remove_all'
     # ./app/services/charge_filters/create_or_update_batch_service.rb:23:in 'ChargeFilters::CreateOrUpdateBatchService#call'
     # ./app/services/base_service.rb:243:in 'block in BaseService.call'
     # ./app/services/base_service.rb:237:in 'BaseService.call'
     # ./spec/services/charge_filters/create_or_update_batch_service_spec.rb:6:in 'block (2 levels) in <top (required)>'
     # ./spec/services/charge_filters/create_or_update_batch_service_spec.rb:101:in 'block (5 levels) in <top (required)>'
     # ./spec/spec_helper.rb:160:in 'block (3 levels) in <top (required)>'
     # ./spec/spec_helper.rb:159:in 'block (2 levels) in <top (required)>'

Finished in 1.48 seconds (files took 1.87 seconds to load)
16 examples, 2 failures

Failed examples:

rspec ./spec/services/charge_filters/create_or_update_batch_service_spec.rb:95 # ChargeFilters::CreateOrUpdateBatchService when filter params is empty when there are existing filters with cascade_updates set to true and existing filters discards all filters and the related values that are inherited from parent
rspec ./spec/services/charge_filters/create_or_update_batch_service_spec.rb:100 # ChargeFilters::CreateOrUpdateBatchService when filter params is empty when there are existing filters with cascade_updates set to true and existing filters does not discard filters and the related values that are defined on child

…tion

As we use some default scopes on models and/or associations using `order`, a warning is logged when we call `find_each` on them.

This commit fixes the warnings by using `unscope(:order)` before calling `find_each`. It also changes the `config.active_record.error_on_ignored_order` to `true` in the test environment to ensure we raise an error instead of logging.
Copy link
Collaborator

@vincent-pochet vincent-pochet left a comment

Choose a reason for hiding this comment

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

🚀

Copy link
Contributor

@julienbourdeau julienbourdeau left a comment

Choose a reason for hiding this comment

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

🙌

@groyoh groyoh merged commit ed46548 into main Jun 27, 2025
14 checks passed
@groyoh groyoh deleted the fix/order-find-each branch June 27, 2025 14:39
diegocharles pushed a commit that referenced this pull request Jul 11, 2025
…tion (#3877)

## Context

As we use some default scopes on models and/or associations using `order`, a warning is logged when we call `find_each` on them.

## Description

This commit fixes the warnings by using `unscope(:order)` before calling `find_each`. It also changes the `config.active_record.error_on_ignored_order` to `true` in the test environment to ensure we raise an error instead of logging.

Example of failed spec:

```shell
bundle exec rspec spec/services/charge_filters/create_or_update_batch_service_spec.rb
                                                                                                                                                                                                                                         
  1) ChargeFilters::CreateOrUpdateBatchService when filter params is empty when there are existing filters with cascade_updates set to true and existing filters discards all filters and the related values that are inherited from parent
     Failure/Error: charge.filters.where(id: inherited_filter_ids).find_each { remove_filter(it) }
     
     ArgumentError:
       Scoped order is ignored, use :cursor with :order to configure custom order.
     # ./app/services/charge_filters/create_or_update_batch_service.rb:118:in 'block in ChargeFilters::CreateOrUpdateBatchService#remove_all'
     # ./app/services/charge_filters/create_or_update_batch_service.rb:116:in 'ChargeFilters::CreateOrUpdateBatchService#remove_all'
     # ./app/services/charge_filters/create_or_update_batch_service.rb:23:in 'ChargeFilters::CreateOrUpdateBatchService#call'
     # ./app/services/base_service.rb:243:in 'block in BaseService.call'
     # ./app/services/base_service.rb:237:in 'BaseService.call'
     # ./spec/services/charge_filters/create_or_update_batch_service_spec.rb:6:in 'block (2 levels) in <top (required)>'
     # ./spec/services/charge_filters/create_or_update_batch_service_spec.rb:96:in 'block (6 levels) in <top (required)>'
     # ./spec/services/charge_filters/create_or_update_batch_service_spec.rb:96:in 'block (5 levels) in <top (required)>'
     # ./spec/spec_helper.rb:160:in 'block (3 levels) in <top (required)>'
     # ./spec/spec_helper.rb:159:in 'block (2 levels) in <top (required)>'

                                                                                                                                                                                                                                         
  2) ChargeFilters::CreateOrUpdateBatchService when filter params is empty when there are existing filters with cascade_updates set to true and existing filters does not discard filters and the related values that are defined on child
     Failure/Error: charge.filters.where(id: inherited_filter_ids).find_each { remove_filter(it) }
     
     ArgumentError:
       Scoped order is ignored, use :cursor with :order to configure custom order.
     # ./app/services/charge_filters/create_or_update_batch_service.rb:118:in 'block in ChargeFilters::CreateOrUpdateBatchService#remove_all'
     # ./app/services/charge_filters/create_or_update_batch_service.rb:116:in 'ChargeFilters::CreateOrUpdateBatchService#remove_all'
     # ./app/services/charge_filters/create_or_update_batch_service.rb:23:in 'ChargeFilters::CreateOrUpdateBatchService#call'
     # ./app/services/base_service.rb:243:in 'block in BaseService.call'
     # ./app/services/base_service.rb:237:in 'BaseService.call'
     # ./spec/services/charge_filters/create_or_update_batch_service_spec.rb:6:in 'block (2 levels) in <top (required)>'
     # ./spec/services/charge_filters/create_or_update_batch_service_spec.rb:101:in 'block (5 levels) in <top (required)>'
     # ./spec/spec_helper.rb:160:in 'block (3 levels) in <top (required)>'
     # ./spec/spec_helper.rb:159:in 'block (2 levels) in <top (required)>'

Finished in 1.48 seconds (files took 1.87 seconds to load)
16 examples, 2 failures

Failed examples:

rspec ./spec/services/charge_filters/create_or_update_batch_service_spec.rb:95 # ChargeFilters::CreateOrUpdateBatchService when filter params is empty when there are existing filters with cascade_updates set to true and existing filters discards all filters and the related values that are inherited from parent
rspec ./spec/services/charge_filters/create_or_update_batch_service_spec.rb:100 # ChargeFilters::CreateOrUpdateBatchService when filter params is empty when there are existing filters with cascade_updates set to true and existing filters does not discard filters and the related values that are defined on child
```
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