I'll let this irb session do the talking (junk omitted with ....).
Create a model with some Marshalled data. user_info is a binary column
irb(main):011:0> p2 = Provider.create(user_info: Marshal.dump(ActiveSupport::HashWithIndifferentAccess.new({foo: 1, bar: 2}))
(0.7ms) BEGIN
SQL (11.6ms) INSERT INTO "providers" (...."user_info") VALUES (....$9) RETURNING "id" [.....["user_info", "\x04\bC:-ActiveSupport::HashWithIndifferentAccess{\aI\"\bfoo\x06:\x06EFi\x06I\"\bbar\x06;\x06Fi\a"]]
(3.6ms) COMMIT
=> #<Provider id: 98, ..... user_info: "\x04\bC:-ActiveSupport::HashWithIndifferentAccess{\aI\"\bf...", provider_id: nil>
Check the value. Looks right:
irb(main):013:0> p2.user_info
=> "\x04\bC:-ActiveSupport::HashWithIndifferentAccess{\aI\"\bfoo\x06:\x06EFi\x06I\"\bbar\x06;\x06Fi\a"
Bad things happen: here I reload it and the value completely changes into a format Marshal can't load
irb(main):014:0> p2.reload
Provider Load (5.3ms) SELECT "providers".* FROM "providers" WHERE "providers"."id" = $1 LIMIT 1 [["id", 98]]
=> #<Provider id: 98, ...., user_info: "x0408433a2d416374697665537570706f72743a3a4861736857...", provider_id: nil>
irb(main):015:0> p2.user_info
=> "x0408433a2d416374697665537570706f72743a3a4861736857697468496e646966666572656e744163636573737b07492208666f6f063a0645466906492208626172063b06466907"
This session is running on Heroku after I recently moved my database from shared to their new free Dev Postgres.
I'm not sure if this is a heroku problem, a postgres problem or a rails problem. The strange thing is: I also migrated another instance (production) of the same app to the new Dev Posgress and it's not having this problem. I found this but it appears to have been fixed years ago. Anyone have experience with this?
Update
Looks like I found an answer after all from this excellent answer on SO: https://stackoverflow.com/a/8541304/65311
ActiveRecord::Store.