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

Do not attempt to convert ActionDispatch::Request/Response to JSON #177

Merged
merged 2 commits into from
Mar 18, 2021

Conversation

alpaca-tc
Copy link
Contributor

Since Rails 6.1, the payload of action dispatch can't be converted.

It's not guaranteed to_json conversion, and SystemStackError got to happen.
To avoid this, fixed to ignore ActionDispatch::Request/ActionDispatch::Response to JSON.

and added test for rails 6.1

@epistrephein
Copy link

Any chance to get a review/merge and a new gem version for this fix?

@zzemla
Copy link

zzemla commented Mar 12, 2021

For anyone interested - a monkey patch based on this PR, which you can put into a file under config/initializers:

if defined?(MetaRequest) && ! MetaRequest::Event.private_instance_methods(false).include?(:not_encodable?)

  MetaRequest::Event.class_eval {

    private

    def json_encodable(payload)
      return {} unless payload.is_a?(Hash)

      transform_hash(payload, deep: true) do |hash, key, value|
        if value.class.to_s == 'ActionDispatch::Http::Headers'
          value = value.to_h.select { |k, _| k.upcase == k }
        elsif not_encodable?(value)
          value = self.class.const_get(:NOT_JSON_ENCODABLE)
        end

        begin
          value.to_json(methods: [:duration])
          new_value = value
        rescue StandardError
          new_value = self.class.const_get(:NOT_JSON_ENCODABLE)
        end
        hash[key] = new_value
      end.with_indifferent_access
    end

    def not_encodable?(value)
      (defined?(ActiveRecord) && value.is_a?(ActiveRecord::ConnectionAdapters::AbstractAdapter)) ||
        (defined?(ActionDispatch) &&
          (value.is_a?(ActionDispatch::Request) || value.is_a?(ActionDispatch::Response)))
    end

  }

end

@dejan
Copy link
Owner

dejan commented Mar 18, 2021

Thanks for the fix!

evazion added a commit to danbooru/danbooru that referenced this pull request Mar 25, 2021
Remove a workaround added in 2c06766. meta_request had a bug that
caused Rails to fail to launch under Rails 6.1. The fix was finally
merged upstream.

hxxps://github.com/dejan/rails_panel/pull/177.
eyupatis added a commit to eyupatis/ruby-tr that referenced this pull request Mar 27, 2021
eyupatis added a commit to eyupatis/ruby-tr that referenced this pull request Apr 2, 2021
MuhammetDilmac pushed a commit to rubytr/ruby-tr that referenced this pull request Apr 2, 2021
* upgrade rails version to rails 6.1.3.1 and ruby version to 2.6.6

* make changes to the files after running rails app:update

* fix small problems on db/schema.rb file

* fix rubocop error

* update contributing documentation to include necessary commands

* remove meta_request gem, because it is not compatible with rails 6.1.x

See rails/rails#40781
and
dejan/rails_panel#177 (comment)
for more details

* change cookies serializer to hybrid to not break existing cookies

For more details:
https://bigbinary.com/blog/migrating-existing-session-cookies-while-upgrading-to-rails-4-1-and-above

* change ruby versions in workflow and .ruby-version file

* add ruby installation step to contributing.md file

* drop old index name for active admin comments

This will be helpful to the developers who had the database and run
migrations in the past. It will basically remove the index with the old
name and it will create the index with the new name.

* rename old index name, instead of dropping it and creating new one
MuhammetDilmac pushed a commit to rubytr/ruby-tr that referenced this pull request Apr 2, 2021
* upgrade rails version to rails 6.1.3.1 and ruby version to 2.6.6

* make changes to the files after running rails app:update

* fix small problems on db/schema.rb file

* fix rubocop error

* update contributing documentation to include necessary commands

* remove meta_request gem, because it is not compatible with rails 6.1.x

See rails/rails#40781
and
dejan/rails_panel#177 (comment)
for more details

* change cookies serializer to hybrid to not break existing cookies

For more details:
https://bigbinary.com/blog/migrating-existing-session-cookies-while-upgrading-to-rails-4-1-and-above

* change ruby versions in workflow and .ruby-version file

* add ruby installation step to contributing.md file

* drop old index name for active admin comments

This will be helpful to the developers who had the database and run
migrations in the past. It will basically remove the index with the old
name and it will create the index with the new name.

* rename old index name, instead of dropping it and creating new one

* update pg gem to v1.2.3
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.

4 participants