From dedbe2a6a50bbe241d3ee71d7c9eaa35e4d2f345 Mon Sep 17 00:00:00 2001 From: Kevin Bruccoleri Date: Thu, 25 Apr 2024 15:30:29 -0400 Subject: [PATCH 1/3] Rails 7.1 Incompatibility: ActionView::Helpers::FormBuilder Due to Rails monkey patching the Object#to_json method, it is possible for an unassuming object to call the method and trigger a error. https://github.com/rails/rails/blob/v7.1.3.2/activesupport/lib/active_support/core_ext/object/json.rb#L63 We discovered a case where this was caused by an instance of ActionView::Helpers::FormBuilder. We extended MetaRequest::Event#not_encodable? to exclude this class and prevent the recursion. --- meta_request/Dockerfile-rails-7.1 | 36 ++++++++++++++++++++++++++ meta_request/lib/meta_request/event.rb | 8 +++--- 2 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 meta_request/Dockerfile-rails-7.1 diff --git a/meta_request/Dockerfile-rails-7.1 b/meta_request/Dockerfile-rails-7.1 new file mode 100644 index 0000000..2a58c06 --- /dev/null +++ b/meta_request/Dockerfile-rails-7.1 @@ -0,0 +1,36 @@ +FROM ruby:3.0-alpine + +RUN apk add --update --no-cache \ + build-base \ + curl-dev \ + git \ + nodejs \ + shared-mime-info \ + sqlite-dev \ + tzdata \ + yaml-dev \ + yarn \ + zlib-dev + +RUN mkdir /app /gem +WORKDIR /app + +RUN gem update --system 3.5.7 +RUN bundle config force_ruby_platform true +RUN gem install rails -v 7.1.3.2 +RUN rails new . + +COPY . /gem +RUN bundle add meta_request --path /gem +RUN bundle install + +COPY res/routes.rb /app/config/ +COPY res/dummy_controller.rb /app/app/controllers/ +COPY res/dummy /app/app/views/dummy +COPY res/meta_request_test.rb /app/test/integration/ + +RUN bundle exec rails db:migrate + +ENV PARALLEL_WORKERS 1 + +CMD ["bin/rake"] diff --git a/meta_request/lib/meta_request/event.rb b/meta_request/lib/meta_request/event.rb index 739df32..d72286f 100644 --- a/meta_request/lib/meta_request/event.rb +++ b/meta_request/lib/meta_request/event.rb @@ -65,9 +65,11 @@ def sanitize_hash(payload) 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))) + return true if defined?(ActiveRecord) && value.is_a?(ActiveRecord::ConnectionAdapters::AbstractAdapter) + return true if defined?(ActionDispatch) && (value.is_a?(ActionDispatch::Request) || value.is_a?(ActionDispatch::Response)) + return true if defined?(ActionView) && value.is_a?(ActionView::Helpers::FormBuilder) + + false end # https://gist.github.com/dbenhur/1070399 From 992de8acfc0559cf6e55e4c12ef2159e43b13cd9 Mon Sep 17 00:00:00 2001 From: Kevin Bruccoleri Date: Tue, 27 Aug 2024 11:36:21 -0400 Subject: [PATCH 2/3] Rails 7.1 Incompatibility: Payload exclude locals Inspired by @abrom in https://github.com/dejan/rails_panel/issues/203: "I've been doing some digging and have found the cause of the SystemStackError being raised when trying to using meta_request with Rails 7.1.x In short it comes down to a change in the instrumentation mechanism to include locals: rails/rails@b451ff0#diff-c92c886291bac7b41bab2a3a884a476ff8edfe2827da7db5ee0bf78c9ad8a17fR250 The problem being that meta_request tries to serialise the render payload to JSON, however the template property of the ActionView objects (if passed through the locals when rendering a template) has cyclic child dependencies (the routes) which can not be serialised. The simple fix would be to exclude that key (locals) in the serialisation to revert the behaviour to pre-Rails 7.1.x as such: payload.except(:locals)" --- meta_request/lib/meta_request/event.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meta_request/lib/meta_request/event.rb b/meta_request/lib/meta_request/event.rb index d72286f..87df1fb 100644 --- a/meta_request/lib/meta_request/event.rb +++ b/meta_request/lib/meta_request/event.rb @@ -61,7 +61,7 @@ def sanitize_hash(payload) payload[:key] = ActiveSupport::Cache::Store.new.send(:normalize_key, payload[:key]) end - payload + payload.except(:locals) end def not_encodable?(value) From 3325276b2c24c13aef8d03c7c11ca5ca4044ad89 Mon Sep 17 00:00:00 2001 From: Kevin Bruccoleri Date: Tue, 27 Aug 2024 11:40:57 -0400 Subject: [PATCH 3/3] Bump gem version --- meta_request/meta_request.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meta_request/meta_request.gemspec b/meta_request/meta_request.gemspec index 644484e..614fe45 100644 --- a/meta_request/meta_request.gemspec +++ b/meta_request/meta_request.gemspec @@ -2,7 +2,7 @@ Gem::Specification.new do |gem| gem.name = 'meta_request' - gem.version = '0.8.2' + gem.version = '0.8.3' gem.summary = 'Request your Rails request' gem.description = 'Supporting gem for Rails Panel (Google Chrome extension for Rails development)'