Commit 58af0f694baeca9e2e6b28a758c950894dc9078d

Authored by Andrew Kane
1 parent 5f145277

Fixed reindex async for non-numeric primary keys in Postgres - fixes #983

Showing 2 changed files with 8 additions and 1 deletions   Show diff stats
@@ -7,6 +7,7 @@ @@ -7,6 +7,7 @@
7 - Raise error for `reindex_status` when Redis not configured 7 - Raise error for `reindex_status` when Redis not configured
8 - Warn when incompatible options used with `body` option 8 - Warn when incompatible options used with `body` option
9 - Fixed bug where `routing` and `type` options were silently ignored with `body` option 9 - Fixed bug where `routing` and `type` options were silently ignored with `body` option
  10 +- Fixed `reindex(async: true)` for non-numeric primary keys in Postgres
10 11
11 ## 2.3.1 12 ## 2.3.1
12 13
lib/searchkick/index.rb
@@ -446,7 +446,13 @@ module Searchkick @@ -446,7 +446,13 @@ module Searchkick
446 # TODO expire Redis key 446 # TODO expire Redis key
447 primary_key = scope.primary_key 447 primary_key = scope.primary_key
448 448
449 - starting_id = scope.minimum(primary_key) 449 + starting_id =
  450 + begin
  451 + scope.minimum(primary_key)
  452 + rescue ActiveRecord::StatementInvalid
  453 + false
  454 + end
  455 +
450 if starting_id.nil? 456 if starting_id.nil?
451 # no records, do nothing 457 # no records, do nothing
452 elsif starting_id.is_a?(Numeric) 458 elsif starting_id.is_a?(Numeric)