Skip to content
This repository has been archived by the owner on Mar 12, 2023. It is now read-only.

[BUG] Not compatible with Rails CurrentAttributes - attributes come back as nil #73

Closed
kaoru opened this issue Oct 10, 2020 · 3 comments · Fixed by #74
Closed

[BUG] Not compatible with Rails CurrentAttributes - attributes come back as nil #73

kaoru opened this issue Oct 10, 2020 · 3 comments · Fixed by #74
Labels
bug Something isn't working wait for release

Comments

@kaoru
Copy link

kaoru commented Oct 10, 2020

Describe the bug

When using jard to debug a Rails application which is using CurrentAttributes the attributes set on the Current object are coming back as nil. When doing the same debugging with pry the attributes on the Current object are set correctly.

To Reproduce

Here's a single file Rails application based on the Rails bug report template for controllers.

# frozen_string_literal: true

require "bundler/inline"

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

  gem "rails"

  #gem "ruby_jard"
  #gem "pry"
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
    get "/" => "test#index"
  end
end

class Current < ActiveSupport::CurrentAttributes
  attribute :request
end

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

  before_action do
    Current.request = request
  end

  def index
    render plain: "Home"
  end
end


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

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

  def test_returns_success
    get "/"

    #jard
    #binding.pry

    assert last_response.ok?
    assert Current.request.uuid.present?
  end

  private

  def app
    Rails.application
  end
end

If you run it as-is the tests should pass.

If you uncomment the Jard lines (lines 10 and 55) then run it again the jard debugger starts up. If you continue out of it the tests pass. But the bug is that on the Jard debugging REPL the Current attributes are nil.

jard >> Current.request.class
=> NilClass
jard >> Current.request.uuid
NoMethodError: undefined method `uuid' for nil:NilClass
from (pry):2:in `test_returns_success'

If you instead uncomment the pry lines (11 and 56) then the tests pass and the Current attributes are accessible through the debugging REPL.

[1] pry(#<BugTest>)> Current.request.class
=> ActionDispatch::Request
[2] pry(#<BugTest>)> Current.request.uuid
=> "2213791d-da75-438d-a1f5-1ab605201111"

Expected behavior

Jard's debugging REPL should behave the same as Pry's and have access to Current.request.

Environment (please complete the following information):

  • OS: Ubuntu 20.04
  • Terminal Emulator: gnome-terminal
  • Output when you run tput colors in your terminal: 256
  • Output when you run echo $TERM in your terminal: xterm-256
  • Output when you run stty: speed 38400 baud; line = 0; -brkint -imaxbel iutf8
  • Do you use tmux/screen or similar tty multiplexer?: no

Also not on your list but I've tried this on Ruby 2.6.6 and 2.7.2, on Rails 6.0.3.4

Thanks ❤️ Jard looks incredible!

@kaoru kaoru added the bug Something isn't working label Oct 10, 2020
@0x2c7
Copy link
Owner

0x2c7 commented Oct 12, 2020

Wow. I'm surprised by the detail level of your bug report. I appreciate your times, and efforts helping me on this. This bug is indeed a big issue. The root cause of this bug is that jard evaluates user input in a seperate thread different the stopping thread. It was a good idea to solve a performance issue at first, but now it turns to be a flawed solution. It would take me a while to implement a permanent fix for this issue. So, I'll let you know when it's ready in master branch 🙏

@kaoru
Copy link
Author

kaoru commented Oct 12, 2020

@nguyenquangminh0711 I thought it might be something like that - sounds like it's quite low-level and fundamental to the architecture, I hope the fix isn't too painful! Thanks for your reply 🙏

@0x2c7
Copy link
Owner

0x2c7 commented Oct 13, 2020

Hi @kaoru, I implemented and deployed a fix in #74. You can try the fix at master branch first. I'll push a relase soon.

gem 'ruby_jard', git: 'https://github.com/nguyenquangminh0711/ruby_jard', ref: 'master'

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working wait for release
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants