Skip to content

Backport(v1.19): record_accessor: return nil when a parent of a nested key is not a hash (#5657) - #5703

Merged
Watson1978 merged 1 commit into
v1.19from
backport-to-v1.19/pr5657
Nov 30, 2026
Merged

Watson1978 merged 1 commit into
v1.19from
backport-to-v1.19/pr5657

Conversation

@github-actions

Copy link
Copy Markdown

Which issue(s) this PR fixes:
Backport #5657
Fixes #5656

What this PR does / why we need it:
A record accessor for a nested key (for example $.log.level) uses Hash#dig. When a value on the way to the key is not a hash or an array, for example a string or a number, dig raises TypeError. delete_nest and set_nest already rescue this error and do nothing, but call_dig did not.

The visible effect is in filter_grep. For <regexp> key $.log.level pattern /error/ </regexp>, a record such as {"log":"plain text line"} made filter_grep log failed to grep events error_class=TypeError error="String does not have #dig method" with a backtrace, and the record was passed through even though it does not match. With this change, call_dig returns nil, the same as when the key does not exist, so <regexp> drops the record and <exclude> keeps it, without any warning.

Other users of a nested record accessor get the same behavior as for a missing key:

  • filter_parser (key_name) emits an error event "does not exist" instead of a TypeError. With reserve_data true, it also passes the record on, as it does for a missing key.
  • formatter_csv writes an empty field.
  • A nested buffer chunk key, such as <buffer $.a.b>, puts the record in the same chunk as records without the key. Before this change, the whole event stream of that emit went to @ERROR, including the valid records. fluent-plugin-rewrite-tag-filter and copy with ignore_if_prev_success also stop sending such records to @ERROR.

Tests: test_record_accessor.rb (string, integer and array parents) and test_filter_grep.rb (<regexp> drops and <exclude> keeps such records, with no "failed to grep events" warning). Both fail on master and pass with this change.

Docs Changes:
N/A

Release Note:
record_accessor: return nil instead of raising TypeError when a value on the way to a nested key is not a hash, the same as for a missing key. This fixes filter_grep passing non-matching records through with a "failed to grep events" warning. A nested buffer chunk key now puts such records in the same chunk as records without the key, instead of sending the whole event stream to @ERROR.

…sh (#5657)

A record accessor for a nested key, such as `$.log.level`, used
Hash#dig, which raises TypeError when a value on the way is not a
hash, for example a string or a number. Unlike delete_nest and
set_nest, call_dig did not handle that error.

As a result, filter_grep logged "failed to grep events" with a
backtrace for every such record and let the record through, even
when it did not match the <regexp> condition. Return nil instead,
the same as when the key does not exist. Other users of a nested
record accessor, such as a nested buffer chunk key, also handle such
a record as one without the key.

Fixes #5656

Signed-off-by: Bahaa Mattar <bahaa.kmattar@gmail.com>
Co-authored-by: Shizuo Fujita <fujita@clear-code.com>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
@Watson1978 Watson1978 added the bug Something isn't working label Nov 30, 2026
@Watson1978 Watson1978 added this to the v1.19.5 milestone Nov 30, 2026
@Watson1978
Watson1978 merged commit e81f67a into v1.19 Nov 30, 2026
21 checks passed
@Watson1978
Watson1978 deleted the backport-to-v1.19/pr5657 branch November 30, 2026 07:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants