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

disable_indexing setting not disabling #448

Open
ColinTheRobot opened this issue Sep 12, 2024 · 0 comments
Open

disable_indexing setting not disabling #448

ColinTheRobot opened this issue Sep 12, 2024 · 0 comments

Comments

@ColinTheRobot
Copy link

ColinTheRobot commented Sep 12, 2024

  • Rails version: 7.1
  • Algolia Rails integration version: 2.3.2
  • Algolia Client Version: none
  • Language Version: 3.0

Description

disable_indexing option is not being read consistently by #algolia_indexing_disabled? resulting indexing happening in the test suite.

Have a very simple setup at this point. One model, Manufacturer. These are the settings/options we are passing.

class Manufacturer
  algoliasearch index_name: "Manufacturer", per_environment: true, raise_on_failure: true, disable_indexing: Rails.env.test? do
    # ...
  end
end

The result when I run a test that creates a Manufacturer is:

     Failure/Error: let(:manufacturer) { create(:manufacturer) }
     
     Algolia::AlgoliaHttpError:
       Index not allowed with this API key

I dug into the library a little and found that in #algolia_index! there are three algolia_configurations that are iterated over. The first one has disable_indexing set as a top level key and #algolia_indexing_disabled? returns true. However, in the subsequent algolia_configurations. disable_indexing is set but it's stored as an instance variable on the settings object

 @hitsPerPage=20,
 @maxValuesPerFacet=10,
 @options={:index_name=>"Manufacturer", :per_environment=>true, :raise_on_failure=>true, disable_indexing: true},
 @searchableAttributes=["unordered(products)", "name", "domain_name"]>

algolia_indexing_disabled? doesn't reach all the way into whatever object that is:


    def algolia_indexing_disabled?(options = nil)
      options ||= algoliasearch_options
      constraint = options[:disable_indexing] || options['disable_indexing']
      case constraint
      when nil
        return false
      when true, false
      # ...
      end
    end

so options[:disable_indexing] || options['disable_indexing'] returns nil when @options={:index_name=>"Manufacturer", :per_environment=>true, :raise_on_failure=>true, disable_indexing: true}

We're getting around it in the meantime by wrapping the whole algoliasearch block in unless Rails.env.test? but having to include that conditional throughout our business logic when we we need to manually reindex etc is not ideal

@ColinTheRobot ColinTheRobot changed the title disable_indexing not setting disable_indexing setting not disabling Sep 12, 2024
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

No branches or pull requests

1 participant