pat / thinking-sphinx

Sphinx/Manticore plugin for ActiveRecord/Rails
http://freelancing-gods.com/thinking-sphinx
MIT License
1.63k stars 469 forks source link

Ruby 3.1 introduces Psych 4 with a breaking change. #1236

Closed jwmeigs closed 1 year ago

jwmeigs commented 1 year ago

YAML.load now aliases safe_load and also doesn't load the aliases without the aliases: true option.

https://stackoverflow.com/questions/71191685/visit-psych-nodes-alias-unknown-alias-default-psychbadalias

This is in settings.rb line 103

jwmeigs commented 1 year ago

NOTE: My mistake. Rails 6.1 only supports Ruby 3.0.x.

This is still an issue with Rails 7.0.x and Ruby 3.1.x

jdelStrother commented 1 year ago

This is fixed in the develop branch but not yet released, AFAIK. For now I patch around it by having this in an initializer:

class ThinkingSphinx::Settings
  # Ruby 3.1 ships with Psych 4, which no longer allows aliases in yml by default.
  # We'd like to be able to use them in thinking_sphinx.yml
  module YAML
    def self.load(str, **args)
      ::YAML.load(str, aliases: true, **args)
    end

    # The unreleased version of TS (> 5.4.0) has started to use safe_load.
    def self.safe_load(...)
      puts "You can remove this patch now #{__FILE__}"
      ::YAML.safe_load(...)
    end
  end
end
pat commented 1 year ago

My apologies for the delay, just published v5.5.0 with the fix.

pat commented 1 year ago

Also, thanks @jwmeigs for reporting the problem! :)