elastic / elastic/elastic-transport-ruby

MultiJson deprecation warning still emitted from Base#perform_request with multi_json >= 1.21 (PR #112 fix incomplete)

Open Beginner friendly
#125 4 comments 5 reactions 0 assignees View on GitHub
Dominant language
Ruby
Stars
6
Forks
23
PR merge metrics
No merged PRs in 30d

Description

### Summary

`multi_json` 1.21.0 deprecated the legacy `MultiJson` constant in favor of `MultiJSON`. PR #112 handled this in the serializer (`Serializer::MultiJson`) by gating on `deprecated_gem_version_loaded?` and calling `::MultiJSON.parse` / `::MultiJSON.generate` for `multi_json >= 1.21.0`.

However, `Base#perform_request` still calls `::MultiJson.adapter` directly, without the same guard. With `multi_json >= 1.21.0` installed this emits, on the first JSON response of every process:

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

### Location

In `lib/elastic/transport/transport/base.rb`, inside `perform_request` (still present on `main`, commit `d192b57`):

```ruby
# Prevent Float value from automatically becoming BigDecimal when using Oj
load_options = {}
load_options[:mode] = :compat if ::MultiJson.adapter.to_s == "MultiJson::Adapters::Oj"
```

`::MultiJson.adapter` is a method call on the legacy constant, which routes through `multi_json`'s deprecation shim and triggers the warning. The serializer at `lib/elastic/transport/transport/serializer/multi_json.rb` is already guarded; this call site was missed.

### Environment

- `elastic-transport` 8.5.2 (and `main`)
- `multi_json` 1.21.1
- Ruby 4.0.1

### Reproduction

```ruby
require 'multi_json' # 1.21.x
Warning[:deprecated] = true
::MultiJson.adapter
# => warning: The MultiJson constant is deprecated and will be removed in v2.0. Use MultiJSON instead.
```

In a real app the warning appears at runtime on the first Elasticsearch response with a JSON `content-type` (once per process, since `multi_json` warns only once per key).

### Suggested fix

Gate the `adapter` lookup the same way the serializer does, e.g.:

```ruby
adapter = deprecated_gem_version_loaded? ? ::MultiJson.adapter : ::MultiJSON.adapter
load_options[:mode] = :compat if adapter.to_s.end_with?('Adapters::Oj')
```

(or expose the existing `deprecated_gem_version_loaded?` helper to `Base`, or compare against both `"MultiJson::Adapters::Oj"` and `"MultiJSON::Adapters::Oj"`).

---
Issue opened with the help of [Claude Code](https://claude.com/claude-code).

Contributor guide

Open the contributing guide

Research direction

Start in lib/elastic/transport/transport/base.rb at Base#perform_request and compare its adapter lookup with the guarded handling in lib/elastic/transport/transport/serializer/multi_json.rb. Reproduce with multi_json 1.21.x and Warning[:deprecated] enabled, then verify that a JSON response no longer emits the legacy MultiJson warning while the Oj compatibility behavior remains intact.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.