FIX: Allow Time objects to be deserialized in PostRevision (stable) (#17502)

Followup to bb287c6c74aed9c9ccd36f6270c219f806bb84f3
This commit is contained in:
David Taylor 2022-07-15 00:17:53 +01:00 committed by GitHub
parent c75ec7335d
commit 5d2ecce3f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 1 deletions

View File

@ -246,7 +246,7 @@ module Discourse
# see: http://stackoverflow.com/questions/11894180/how-does-one-correctly-add-custom-sql-dml-in-migrations/11894420#11894420
config.active_record.schema_format = :sql
config.active_record.yaml_column_permitted_classes = [Hash, HashWithIndifferentAccess]
config.active_record.yaml_column_permitted_classes = [Hash, HashWithIndifferentAccess, Time]
# We use this in development-mode only (see development.rb)
config.active_record.use_schema_cache_dump = false

View File

@ -0,0 +1,26 @@
# frozen_string_literal: true
describe PostRevision do
it "can deserialize old YAML" do
# Date objects are stored in core post_revisions prior
# to https://github.com/discourse/discourse/commit/e7f251c105
# and are also stored by some plugins
pr = Fabricate(:post_revision)
DB.exec("UPDATE post_revisions SET modifications = ?", <<~YAML)
---
last_version_at:
- 2013-12-12 21:40:13.225239000 Z
- 2013-12-12 22:10:51.433689320 Z
YAML
pr.reload
expect(pr.modifications).to eq(
{
"last_version_at" => [
Time.parse("2013-12-12 21:40:13.225239000 Z"),
Time.parse("2013-12-12 22:10:51.433689320 Z")
]
}
)
end
end