Skip to content

fix: normalize attribute keys to symbols#6

Merged
bharget merged 1 commit intomainfrom
ben/fix-string-keys
Dec 18, 2025
Merged

fix: normalize attribute keys to symbols#6
bharget merged 1 commit intomainfrom
ben/fix-string-keys

Conversation

@bharget
Copy link
Copy Markdown
Owner

@bharget bharget commented Dec 18, 2025

Summary

Fixes a bug where passing attributes with string keys (e.g., from Rails params) would not properly override defaults.

Problem

The defaults hash uses symbol keys, but attributes.key?(key) failed when attributes had string keys:

# Before fix - broken with string keys
Service.new("name" => "John").computed  # callable saw default, not "John"

Solution

Normalize attribute keys to symbols at the start of initialize:

attributes = attributes.transform_keys(&:to_sym)

Tests

Added specs for string key handling with both static and callable defaults.

@bharget bharget force-pushed the ben/fix-string-keys branch from 59f6446 to f769c61 Compare December 18, 2025 02:15
@bharget bharget changed the base branch from ben/callable-defaults to main December 18, 2025 02:15
@bharget bharget merged commit f0e61ea into main Dec 18, 2025
4 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