Permalink
Browse files

fix 2.1.0 bug :(

  • Loading branch information...
1 parent 707be60 commit d0926d3d5e8ad9378c5f976db819d8c949314b59 @schneems schneems committed Dec 25, 2013
Showing with 1 addition and 1 deletion.
  1. +1 −1 railties/test/application/rake/dbs_test.rb
@@ -24,7 +24,7 @@ def set_database_url
# ensure it's using the DATABASE_URL
FileUtils.rm_rf("#{app_path}/config/database.yml")
File.open("#{app_path}/config/database.yml", 'w') do |f|
- f << {ENV['RAILS_ENV'] => '<%= ENV["RAILS_DATABASE_URL"] %>'}.to_yaml
+ f << {ENV['RAILS_ENV'] => %Q{<%= ENV['RAILS_DATABASE_URL'] %>}}.to_yaml
end
end

3 comments on commit d0926d3

Contributor

charliesome replied Dec 27, 2013

This will just break again next time Psych changes its quoting rules, which IMO it should be perfectly free to do.

Why not do something like this instead?

f << "#{ENV["RAILS_ENV"]}: <%= ENV['RAILS_DATABASE_URL'] %>\n"
Member

schneems replied Dec 27, 2013

Thats what I had at first, but then i said to myself, "Wait, ruby knows more about YAML thank I do, i'll let it build the syntax for me!"

This was a minor bump, so small incompatibilities are to be expected. If Psych could rev the quoting rules between point releases, then it would seem having psych quote for you is not guaranteed to be compatible moving forwards, and therefore not supported. It also means data written to disk via older versions 1.9.2, 1.9.3, 2.0.0 are not correctly read-able via 2.1.0 if you're using quotes. If we cannot lock down this behavior, and cannot "fix" it, can we somehow warn or deprecate use of quotes within Psych parsed strings?

We use YAML to write to disk on the buildpack https://github.com/heroku/heroku-buildpack-ruby/blob/master/lib/language_pack/base.rb#L96. At the moment we're not using any quoted strings, but that requirement could change in the future. Should we switch to manually building YAML?

Contributor

charliesome replied Dec 28, 2013

If Psych could rev the quoting rules between point releases, then it would seem having psych quote for you is not guaranteed to be compatible moving forwards, and therefore not supported. It also means data written to disk via older versions 1.9.2, 1.9.3, 2.0.0 are not correctly read-able via 2.1.0 if you're using quotes.

Psych can still correctly read the YAML emitted by 1.9.2, 1.9.3 and 2.0.0, as it's valid YAML:

>> RUBY_VERSION
=> "2.1.0"
>> YAML.load("a: <%= ENV['blah'] %>")
=> {"a"=>"<%= ENV['blah'] %>"}

What's happened here is that Psych has changed the rules it uses to emit YAML so that it now emits an alternate, but still valid as per the YAML spec, syntax for strings with funky symbols in them. I think this is a perfectly justifiable change.

Where you're running into problems is that you're not using Psych to emit YAML, you're using Psych to emit a very similar but different language - YAML with ERB. Because Psych is a YAML parser/dumper and not a 'YAML with ERB' parser/dumper, it is not required to maintain support for the quoting rules you're relying on to make 'YAML with ERB' work.

Please sign in to comment.