Skip to content

Fix Type#deserialize to handle arrays for multiple: true attributes#473

Merged
nashby merged 1 commit intobrainspec:masterfrom
segiddins:segiddins/deserialize-multiple
Jan 27, 2026
Merged

Fix Type#deserialize to handle arrays for multiple: true attributes#473
nashby merged 1 commit intobrainspec:masterfrom
segiddins:segiddins/deserialize-multiple

Conversation

@segiddins
Copy link
Copy Markdown
Contributor

Previously, deserializing an array would return nil instead of the enumerated values. This bug only affected ActiveModel::Attributes usage (not ActiveRecord) and was exposed when used with gems like store_model v2.0.0+ that call deserialize during load.

The fix checks if the value is an array AND the attribute is declared with multiple: true, then uses find_values(*value) instead of find_value(value).

Added 10 test cases covering:

  • Single value deserialization (existing behavior)
  • Array deserialization for multiple: true attributes
  • Array rejection for non-multiple attributes
  • Empty arrays, nil handling, and invalid value filtering
  • Round-trip serialization for both single and multiple values

Previously, deserializing an array would return nil instead of the
enumerated values. This bug only affected ActiveModel::Attributes usage
(not ActiveRecord) and was exposed when used with gems like store_model
v2.0.0+ that call deserialize during load.

The fix checks if the value is an array AND the attribute is declared
with multiple: true, then uses find_values(*value) instead of
find_value(value).

Added 10 test cases covering:
- Single value deserialization (existing behavior)
- Array deserialization for multiple: true attributes
- Array rejection for non-multiple attributes
- Empty arrays, nil handling, and invalid value filtering
- Round-trip serialization for both single and multiple values
@nashby nashby merged commit 1b84587 into brainspec:master Jan 27, 2026
114 of 120 checks passed
@nashby
Copy link
Copy Markdown
Member

nashby commented Jan 27, 2026

@segiddins thank you!

@segiddins
Copy link
Copy Markdown
Contributor Author

@nashby thanks for merging! any chance I can ask you to cut a release when you have the time? thanks!

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.

2 participants