Skip to content

fix: declare the coder for the custom column - #22

Merged
danquinney merged 2 commits into
mainfrom
fix/serialize-coder
Aug 30, 2026
Merged

fix: declare the coder for the custom column#22
danquinney merged 2 commits into
mainfrom
fix/serialize-coder

Conversation

@danquinney

@danquinney danquinney commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

Why

Apps that adopt config.load_defaults 7.1 get active_record.default_column_serializer = nil, and from Rails 7.1 serialize then insists on an explicit coder:

missing keyword: :coder If no default coder is configured, a coder must be provided to `serialize`.

Attach::Attachment declares serialize :custom, type: Hash, default: {} without one, and because Attach::Railtie loads the model during initialization the host app fails to boot. Found while moving Dial 9 Connect to load_defaults 7.1.

Change

serialize :custom, coder: YAML, type: Hash, default: {} — same on-disk format as today (YAML), just declared explicitly. Active Record < 7.1 ignores the keyword, exactly as it already ignores type: from 2.0.3, so the support floor is unchanged.

Verification

Second commit fixes the test setup so the CI matrix can actually run again (nothing else changed): MigrationContext.new only takes the schema migration class before 7.1, logger is required explicitly for Rails < 7.1 on concurrent-ruby ≥ 1.3.5, and the Rails 6 gemfile pins sqlite3 ~> 1.4 (the 6.1 adapter's requirement, which 2.x broke on Ruby ≥ 3.0).

Local runs of the matrix corners, all 40 examples, 0 failures:

Ruby rails6.gemfile rails7.gemfile
2.7.5 Active Record 6.1.7 Active Record 7.0.10
3.2.10 Active Record 6.1.7 Active Record 7.2.3

Also checked that booting the model with ActiveRecord::Base.default_column_serializer = nil (what load_defaults 7.1 does) loads and reports ActiveRecord::Coders::YAMLColumn as the custom coder with this change, and raises the error above without it.

Applications on `config.load_defaults 7.1` run with
`default_column_serializer = nil`, and Active Record then requires every
`serialize` call to name its coder; Attach::Attachment failed to load with
"missing keyword: :coder". Naming YAML keeps the existing storage format.
Older Active Record versions ignore the keyword, as they already do for
`type:`.
@danquinney
danquinney force-pushed the fix/serialize-coder branch from 59d43db to 80d31b3 Compare August 30, 2026 12:22
Three things had rotted under the CI matrix: MigrationContext.new no longer
takes the schema migration class from 7.1 (and 6.1 still requires it), Rails
< 7.1 needs logger required explicitly since concurrent-ruby 1.3.5, and the
Rails 6 gemfile resolved sqlite3 2.x on Ruby >= 3.0 where the 6.1 adapter
wants ~> 1.4. Verified on Ruby 2.7 and 3.2 with both gemfiles.

Claude-Session: https://claude.ai/code/session_01QDRJWFWvDq5Nu6aWm4gY6t
@danquinney
danquinney merged commit ec78926 into main Aug 30, 2026
14 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