Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds option to YAML load of database.yml so that Psych doesn't complain. #10

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

infews
Copy link

@infews infews commented Feb 5, 2024

I ran install against a Rails 7.1 app and got this stack trace:

❯ bin/rake test_data:install
   identical  config/environments/test_data.rb
   identical  config/initializers/test_data.rb
rake aborted!
Psych::AliasesNotEnabled: Alias parsing was not enabled. To enable it, pass `aliases: true` to `Psych::load` or `Psych::safe_load`. (Psych::AliasesNotEnabled)
/Users/dwfrank/workspace/meals/vendor/bundle/ruby/3.2.0/gems/psych-5.1.2/lib/psych/visitors/to_ruby.rb:432:in `visit_Psych_Nodes_Alias'
/Users/dwfrank/workspace/meals/vendor/bundle/ruby/3.2.0/gems/psych-5.1.2/lib/psych/visitors/visitor.rb:30:in `visit'
/Users/dwfrank/workspace/meals/vendor/bundle/ruby/3.2.0/gems/psych-5.1.2/lib/psych/visitors/visitor.rb:6:in `accept'
/Users/dwfrank/workspace/meals/vendor/bundle/ruby/3.2.0/gems/psych-5.1.2/lib/psych/visitors/to_ruby.rb:35:in `accept'
/Users/dwfrank/workspace/meals/vendor/bundle/ruby/3.2.0/gems/psych-5.1.2/lib/psych/visitors/to_ruby.rb:347:in `block in revive_hash'
/Users/dwfrank/workspace/meals/vendor/bundle/ruby/3.2.0/gems/psych-5.1.2/lib/psych/visitors/to_ruby.rb:345:in `each'
/Users/dwfrank/workspace/meals/vendor/bundle/ruby/3.2.0/gems/psych-5.1.2/lib/psych/visitors/to_ruby.rb:345:in `each_slice'
/Users/dwfrank/workspace/meals/vendor/bundle/ruby/3.2.0/gems/psych-5.1.2/lib/psych/visitors/to_ruby.rb:345:in `revive_hash'
/Users/dwfrank/workspace/meals/vendor/bundle/ruby/3.2.0/gems/psych-5.1.2/lib/psych/visitors/to_ruby.rb:169:in `visit_Psych_Nodes_Mapping'
/Users/dwfrank/workspace/meals/vendor/bundle/ruby/3.2.0/gems/psych-5.1.2/lib/psych/visitors/visitor.rb:30:in `visit'
/Users/dwfrank/workspace/meals/vendor/bundle/ruby/3.2.0/gems/psych-5.1.2/lib/psych/visitors/visitor.rb:6:in `accept'
/Users/dwfrank/workspace/meals/vendor/bundle/ruby/3.2.0/gems/psych-5.1.2/lib/psych/visitors/to_ruby.rb:35:in `accept'
/Users/dwfrank/workspace/meals/vendor/bundle/ruby/3.2.0/gems/psych-5.1.2/lib/psych/visitors/to_ruby.rb:347:in `block in revive_hash'
/Users/dwfrank/workspace/meals/vendor/bundle/ruby/3.2.0/gems/psych-5.1.2/lib/psych/visitors/to_ruby.rb:345:in `each'
/Users/dwfrank/workspace/meals/vendor/bundle/ruby/3.2.0/gems/psych-5.1.2/lib/psych/visitors/to_ruby.rb:345:in `each_slice'
/Users/dwfrank/workspace/meals/vendor/bundle/ruby/3.2.0/gems/psych-5.1.2/lib/psych/visitors/to_ruby.rb:345:in `revive_hash'
/Users/dwfrank/workspace/meals/vendor/bundle/ruby/3.2.0/gems/psych-5.1.2/lib/psych/visitors/to_ruby.rb:169:in `visit_Psych_Nodes_Mapping'
/Users/dwfrank/workspace/meals/vendor/bundle/ruby/3.2.0/gems/psych-5.1.2/lib/psych/visitors/visitor.rb:30:in `visit'
/Users/dwfrank/workspace/meals/vendor/bundle/ruby/3.2.0/gems/psych-5.1.2/lib/psych/visitors/visitor.rb:6:in `accept'
/Users/dwfrank/workspace/meals/vendor/bundle/ruby/3.2.0/gems/psych-5.1.2/lib/psych/visitors/to_ruby.rb:35:in `accept'
/Users/dwfrank/workspace/meals/vendor/bundle/ruby/3.2.0/gems/psych-5.1.2/lib/psych/visitors/to_ruby.rb:320:in `visit_Psych_Nodes_Document'
/Users/dwfrank/workspace/meals/vendor/bundle/ruby/3.2.0/gems/psych-5.1.2/lib/psych/visitors/visitor.rb:30:in `visit'
/Users/dwfrank/workspace/meals/vendor/bundle/ruby/3.2.0/gems/psych-5.1.2/lib/psych/visitors/visitor.rb:6:in `accept'
/Users/dwfrank/workspace/meals/vendor/bundle/ruby/3.2.0/gems/psych-5.1.2/lib/psych/visitors/to_ruby.rb:35:in `accept'
/Users/dwfrank/workspace/meals/vendor/bundle/ruby/3.2.0/gems/psych-5.1.2/lib/psych.rb:334:in `safe_load'
/Users/dwfrank/workspace/meals/vendor/bundle/ruby/3.2.0/gems/psych-5.1.2/lib/psych.rb:660:in `block in safe_load_file'
/Users/dwfrank/workspace/meals/vendor/bundle/ruby/3.2.0/gems/psych-5.1.2/lib/psych.rb:659:in `open'
/Users/dwfrank/workspace/meals/vendor/bundle/ruby/3.2.0/gems/psych-5.1.2/lib/psych.rb:659:in `safe_load_file'
/Users/dwfrank/workspace/meals/vendor/bundle/ruby/3.2.0/gems/test_data-0.3.2/lib/test_data/config.rb:98:in `database_yaml'
/Users/dwfrank/workspace/meals/vendor/bundle/ruby/3.2.0/gems/test_data-0.3.2/lib/test_data/configurators/database_yaml.rb:10:in `verify'
/Users/dwfrank/workspace/meals/vendor/bundle/ruby/3.2.0/gems/test_data-0.3.2/lib/generators/test_data/database_yaml_generator.rb:7:in `call'
/Users/dwfrank/workspace/meals/vendor/bundle/ruby/3.2.0/gems/test_data-0.3.2/lib/test_data/configurators/database_yaml.rb:20:in `configure'
/Users/dwfrank/workspace/meals/vendor/bundle/ruby/3.2.0/gems/test_data-0.3.2/lib/test_data/installs_configuration.rb:5:in `block in call'
/Users/dwfrank/workspace/meals/vendor/bundle/ruby/3.2.0/gems/test_data-0.3.2/lib/test_data/installs_configuration.rb:4:in `each'
/Users/dwfrank/workspace/meals/vendor/bundle/ruby/3.2.0/gems/test_data-0.3.2/lib/test_data/installs_configuration.rb:4:in `call'
/Users/dwfrank/workspace/meals/vendor/bundle/ruby/3.2.0/gems/test_data-0.3.2/lib/test_data/rake.rb:40:in `block in <main>'
Tasks: TOP => test_data:install => test_data:configure
(See full trace by running task with --trace)

I'm not sure why this wouldn't happen always, but FWIW, this is my database.yml

# SQLite. Versions 3.8.0 and up are supported.
#   gem install sqlite3
#
#   Ensure the SQLite 3 gem is defined in your Gemfile
#   gem "sqlite3"
#
default: &default
  adapter: sqlite3
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  timeout: 5000

development:
  <<: *default
  database: db/development.sqlite3

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
  <<: *default
  database: db/test.sqlite3

production:
  <<: *default
  database: db/production/production.sqlite3

This change to config.rb got what looks like the right lines are inserted into my database.yml

@@ -97,7 +97,7 @@ def after_rails_fixture_load(callable = nil, &blk)
end

def database_yaml
YAMLLoader.load_file(database_yaml_full_path)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 I thought my changes in that file fixed this issue - but perhaps I missed something.

YAMLLoader is just wrapping YAML, and forcing aliases in the event of it needing to.

https://github.com/testdouble/test_data/blob/main/lib/test_data/yaml_loader.rb#L3-L5

The YAMLLoader.load_file method doesn't take a second argument.

It's still not working on your end?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. Which is why I added the flag.

Copy link
Contributor

@thewatts thewatts Feb 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry if what I said was a little confusing.

Where you added that flag -> that method doesn't take in a second argument. YAMLLoader is a wrapper around YAML, that attempts to take care of the alias problem.

Were you using the most recent gem release? That doesn't have the YAMLLoader changes in it.

I'm assuming that the maintainer isn't going to cut a new release until full 7.1 support is available (it's a work in progress at the moment).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Def using the gem release.

I've dropped this gem for now b/c I'm using SQLite and doing a full extraction for an alternate DB adapter is beyond what I have time for right now. Will look again later. Thanks!

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.

2 participants