bricolages / bricolage

AWS-oriented Data Warehouse Framework
113 stars 20 forks source link

use YAML.unsafe_load instead of YAML.load to maintain compatibility #178

Open kangaechu opened 11 months ago

kangaechu commented 11 months ago

Environment

Details

I got an following error.

eval error: /home/user/app/importer/config/variable.yml: config file syntax error: Tried to load unspecified class: Date

importer/config/variable.yml:

<%
require 'date'

target_day = ENV['TARGET_DAY']
today = Date.parse(target_day)
%>
target_day: <%= target_day %>

Since Ruby 3.1.0, Psych has been updated to 4.0.0. Psych 4.0.0 has incompatible changes. In Psych 4.0.0, YAML.load uses Psych.safe_load internally. Previous versions of Psych.load can also be used with Psych.unsafe_load. Psych.safe_load is a safer way to load YAML data than Psych.load. By default, Psych.safe_load only converts objects of the following classes: TrueClass, FalseClass, NilClass, Numeric, String, Array, and Hash. Psych.safe_load also does not allow the use of YAML aliases. Because of this difference between Psych.load and Psych.safe_load, YAML data that was previously loadable may no longer load. Therefore, YAML.unsafe_load is used instead of YAML.load to maintain compatibility.

https://secret-garden.hatenablog.com/entry/2021/05/23/200803 (Japanese)

nekketsuuu commented 11 months ago

How about quoting a value on the YAML side? Like,

target_day: "<%= target_day %>"

Or, did you use target_day variable as a Date instance instead of String?