Skip to content

fix(yes-core): honour prefix for array values in HashUtils.deep_flatten_hash#31

Merged
aroeczek merged 1 commit into
mainfrom
fix/deep-flatten-hash-array-prefix
Jun 16, 2026
Merged

fix(yes-core): honour prefix for array values in HashUtils.deep_flatten_hash#31
aroeczek merged 1 commit into
mainfrom
fix/deep-flatten-hash-array-prefix

Conversation

@aroeczek

Copy link
Copy Markdown
Contributor

What

Yes::Core::Utils::HashUtils.deep_flatten_hash applied the prefix to scalar and nested-hash keys, but not to array-valued keys — the String|Symbol, Array branch keyed them by the bare key.to_s:

in String | Symbol, Array
  memo[key.to_s] = deep_flatten_hash(value)            # before — prefix dropped
  memo[prefix ? "#{prefix}.#{key}" : key.to_s] = ...   # after  — prefix honoured

So a caller passing a prefix got a mix of namespaced and un-namespaced keys, e.g.:

deep_flatten_hash({ id: 1, tags: [{ k: 'v' }] }, 'span')
# before => { "span.id" => 1, "tags" => [{ "k" => "v" }] }
# after  => { "span.id" => 1, "span.tags" => [{ "k" => "v" }] }

Why

Discovered while adding webhook.* OpenTelemetry span attributes in application_management_system, where the un-prefixed array keys (assignees, documents) escaped the webhook. namespace and had to be re-namespaced with a transform_keys workaround. This makes the helper consistent so that workaround can be dropped once released.

Safety

Callers that pass no prefix are unaffected — with prefix = nil both branches produce key.to_s (every existing caller in the codebase calls it without a prefix).

Tests

Adds deep_flatten_hash coverage (flat, nested, prefixed scalar/hash, prefixed array regression, no-prefix array) and a deep_dup test. CHANGELOG entry under Unreleased.

🤖 Generated with Claude Code

…en_hash

The `String|Symbol, Array` branch keyed array values by their bare name
(`key.to_s`), ignoring the `prefix` that scalar and nested-hash keys honour.
Callers passing a prefix therefore got a mix of namespaced and un-namespaced
keys (e.g. `deep_flatten_hash({ tags: [...] }, 'span')` produced `"tags"`
instead of `"span.tags"`). Apply the prefix consistently. Callers passing no
prefix are unaffected. Adds spec coverage for deep_flatten_hash and deep_dup.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@aroeczek aroeczek merged commit 678abb0 into main Jun 16, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant