opensearch-project / opensearch-project/opensearch-ruby

MultiJson constant deprecation warning emitted at every boot on 3.4.0 (multi_json 1.21.1)

Open Beginner friendly
#329 0 comments 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

untriaged
Dominant language
Ruby
Stars
114
Forks
60
PR merge metrics
No merged PRs in 30d

Description

Summary

opensearch-ruby 3.4.0's default JSON serializer references the deprecated camelCase ::MultiJson constant. As of multi_json 1.21.1 the canonical constant is MultiJSON (all-caps), and MultiJson is a one-time-deprecation forwarder. Every Rails boot that performs an OpenSearch request prints:

The MultiJson constant is deprecated and will be removed in v2.0. Use MultiJSON instead.
MultiJSON.load is deprecated and will be removed in v2.0. Use MultiJSON.parse instead.

PR #290 already removed multi_json from main (now 4.0.0-beta.5+) by switching to the json gem. However, the latest stable release of opensearch-ruby is 3.4.0 (2024-07-11), which still ships the Serializer::MultiJson class unchanged — and 4.0.0 is still in beta, so production users on stable 3.x see the deprecation noise on every boot.

Reproduce
require 'multi_json'      # 1.21.1
require 'opensearch'      # 3.4.0
require 'warning'         # optional, just to surface :deprecated
Warning[:deprecated] = true

OpenSearch::Client.new(url: 'http://localhost:9200').indices.exists?(index: 'whatever')
# => emits the two deprecation warnings above
Source

lib/opensearch/transport/transport/serializer/multi_json.rb at the 3.4.0 tag:

class MultiJson
  include Base

  def load(string, options = {})
    ::MultiJson.load(string, options)   # deprecated constant + deprecated alias
  end

  def dump(object, options = {})
    ::MultiJson.dump(object, options)   # deprecated constant + deprecated alias
  end
end

Two separate deprecations are involved:

  1. The camelCase ::MultiJson constant (deprecated in multi_json 1.21.1 in favor of ::MultiJSON).
  2. The load / dump method aliases (deprecated in favor of parse / generate).
Suggested fix for the 3.x line

Backport a minimal change so 3.x users on multi_json 1.21.1+ don't see deprecation noise:

def load(string, options = {})
  ::MultiJSON.parse(string, options)
end

def dump(object, options = {})
  ::MultiJSON.generate(object, options)
end

Class name Serializer::MultiJson can stay (renaming it would be a breaking change for anyone passing a custom serializer_class:); only the internal delegators need to move to the canonical API.

Workaround

Until a release, downstream apps can prepend a module on OpenSearch::Transport::Transport::Serializer::MultiJson that overrides load / dump to call ::MultiJSON.parse / ::MultiJSON.generate directly. That silences both warnings without touching the gem.

Versions
  • opensearch-ruby 3.4.0
  • multi_json 1.21.1
  • Ruby 3.4.8
  • Rails 8.1.3 (server: Falcon)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with lib/opensearch/transport/transport/serializer/multi_json.rb and reproduce the request using multi_json 1.21.1 and OpenSearch 3.4.0 as shown. Update the serializer delegators so the request no longer emits the deprecated constant or method warnings, while keeping Serializer::MultiJson unchanged.

Written by the indexing model from the issue text.

Assessment

Tech stack
rails, ruby
Domain
api, backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
84/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.