Skip to content

fix: defer Active Record patching via ActiveSupport.on_load#61

Open
MattyMc wants to merge 1 commit into
palkan:masterfrom
MattyMc:fix-json-type-eager-load
Open

fix: defer Active Record patching via ActiveSupport.on_load#61
MattyMc wants to merge 1 commit into
palkan:masterfrom
MattyMc:fix-json-type-eager-load

Conversation

@MattyMc

@MattyMc MattyMc commented Jun 4, 2026

Copy link
Copy Markdown

Previously, requiring the gem force-loaded active_record/type/json during Bundler.require, before app initializers, so initializers that configure the JSON encoder (e.g., Oj::Rails.set_encoder) had no effect on json/jsonb columns in some Rails versions (e.g. 8.1.2). Now the patches load when ActiveRecord::Base does.

This follows Rails’ recommended pattern for applying configuration to framework classes: use a lazy load hook to avoid autoloading the class before initialization has completed. See the Rails guide note on Avoid Loading Rails Frameworks.

Fixes #60

  • I've added tests for this change
  • I've added a Changelog entry
  • I've updated a documentation (Readme) – N/A

Previously, requiring the gem force-loaded active_record/type/json during Bundler.require, before app initializers, so initializers that configure the JSON encoder (e.g., Oj::Rails.set_encoder) had no effect on json/jsonb columns in some Rails versions (e.g. 8.1.2). Now the patches load when ActiveRecord::Base does.

Closes palkan#60
@MattyMc

MattyMc commented Jun 4, 2026

Copy link
Copy Markdown
Author

Note: the railsmaster CI failure is not caused by this change. It also happens on an untouched master checkout. The latest pglite gem (0.1.1) is missing some connection methods that the latest Rails now calls (close, finished?, status) and its WASM build crashes when Rails sets the session time zone, which edge Rails now does on every new connection. It can be safely ignored.

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.

Avoid eager-loading active_record/type/json.rb

1 participant