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

Active false causes TypeError when using kaminari #375

Open
bendangelo opened this issue Dec 18, 2024 · 1 comment · May be fixed by #376
Open

Active false causes TypeError when using kaminari #375

bendangelo opened this issue Dec 18, 2024 · 1 comment · May be fixed by #376

Comments

@bendangelo
Copy link

I turned off calls during testing and got this error.

Description
Set active false, then run any search. It will cause this error.

Expected behavior

MeiliSearch::Rails.configuration = {
...
  active: !Rails.env.test?
}
class Document
# meilisearch here
end
Document.search "something" # returns empty array

Current behavior
Throws type error

TypeError: no implicit conversion of MeiliSearch::Rails::NullObject into Integer

From: /home/bendangelo/.asdf/installs/ruby/3.3.6/lib/ruby/gems/3.3.0/gems/kaminari-core-1.2.2/lib/kaminari/models/array_extension.rb:26 Kaminari::PaginatableArray#initialize:
                                                                                                
    18: def initialize(original_array = [], limit: nil, offset: nil, total_count: nil, padding: nil)                                         
    19:   @_original_array, @_limit_value, @_offset_value, @_total_count, @_padding = original_array, (limit || default_per_page).to_i, offset.to_i, total_count, padding.to_i
    20:                                         
    21:   if limit && offset                                                                    
    22:     extend Kaminari::PageScopeMethods                                                   
    23:   end                                                                                                                                                                                   
    24:                                                                                         
    25:   if @_total_count && (@_total_count <= original_array.count)
 => 26:     original_array = original_array.first(@_total_count)[@_offset_value, @_limit_value]
    27:   end                                         

Screenshots or Logs
#0 [method] first <Array#first(n=?)>
=> #1 [method] initialize <Kaminari::PaginatableArray#initialize(original_array=?, ?, ?, ?, ?)>
#2 [method] initialize <MeiliSearch::Rails::Pagination::Kaminari#initialize(array, options)>
#3 [method] create <MeiliSearch::Rails::Pagination::Kaminari.create(results, total_hits, options=?)>
#4 [method] load_pagination! <MeiliSearch::Rails::Pagination.load_pagination!(pagination_backend, results, total_hits, options)>
#5 [method] create <MeiliSearch::Rails::Pagination.create(results, total_hits, options=?)>
#6 [method] ms_search <MeiliSearch::Rails::ClassMethods#ms_search(query, params=?)>

Environment (please complete the following information):

  • OS: [e.g. Debian GNU/Linux]
  • Meilisearch server version: [e.g. v.0.20.0]
  • meilisearch-rails version: [e.g v0.1.0]
  • Rails version: [e.g. 6.1.3.2]
@bendangelo
Copy link
Author

bendangelo commented Dec 18, 2024

Edit: Looks like this is hit when a query returns no results?

This is my config:

MeiliSearch::Rails.configuration = {
  meilisearch_url: Rails.application.credentials.meilisearch_url,
  meilisearch_api_key: Rails.application.credentials.meilisearch_api_key,
  per_environment: true,
  pagination_backend: :kaminari,
  timeout: 2,
  max_retries: 1,
  active: !Rails.env.test?
}

@bendangelo bendangelo linked a pull request Dec 19, 2024 that will close this issue
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 a pull request may close this issue.

1 participant