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

params.to_yaml fails with TypeError (can't dump anonymous module ) in Rails 7 #44743

Closed
RogerE opened this issue Mar 22, 2022 · 2 comments · Fixed by #44749
Closed

params.to_yaml fails with TypeError (can't dump anonymous module ) in Rails 7 #44743

RogerE opened this issue Mar 22, 2022 · 2 comments · Fixed by #44749

Comments

@RogerE
Copy link

RogerE commented Mar 22, 2022

After upgrading to Rails 7 doing params.to_yaml in a controller fails with TypeError (can't dump anonymous module ). Works in Rails 6.

Steps to reproduce

# frozen_string_literal: true

require "bundler/inline"

gemfile(true) do
  source "https://rubygems.org"

  git_source(:github) { |repo| "https://github.com/#{repo}.git" }

  gem "rails", github: "rails/rails", branch: "main"
end

require "action_controller/railtie"

class TestApp < Rails::Application
  config.root = __dir__
  config.hosts << "example.org"
  secrets.secret_key_base = "secret_key_base"

  config.logger = Logger.new($stdout)
  Rails.logger  = config.logger

  routes.draw do
    post "/" => "test#index"
  end
end

class TestController < ActionController::Base
  include Rails.application.routes.url_helpers

  def index
    params_yaml = params.to_yaml
    render plain: "Home"
  end
end

require "minitest/autorun"
require "rack/test"

class BugTest < Minitest::Test
  include Rack::Test::Methods

  def test_returns_success
    post '/', params: { custom: "a", item_number: "123" }
    assert last_response.ok?
  end

  private
    def app
      Rails.application
    end
end

Expected behavior

Submited parameters should be returned as YAML

Actual behavior

Request fails with TypeError (can't dump anonymous module )

System configuration

Rails version: example code is with branch: "main" (Affects all version from 7.0.0 and up as far as I can tell)

Ruby version: 2.7.5

@skipkayhil
Copy link
Member

skipkayhil commented Mar 22, 2022

It looks like 6be9c49 is causing this. Dumping params now includes @logging_context, which is failing because it includes the request object some anonymous class nested in the request object

@RogerE
Copy link
Author

RogerE commented Mar 23, 2022

Thanks for the fix @skipkayhil , appreciated!

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 a pull request may close this issue.

2 participants