padrino / padrino-framework

Padrino is a full-stack ruby framework built upon Sinatra.
http://www.padrinorb.com
MIT License
3.37k stars 508 forks source link

Padrino (v. 0.15.3) fails to start with Ruby 3.3.0: uninitialized constant Padrino::Rackup (NameError) #2288

Open kimberlykeilymh opened 7 months ago

kimberlykeilymh commented 7 months ago

Do you want to request a feature or report a bug?

Bug

What is the current behavior?

Failure to start server using Ruby 3.3.0. Below is the stack trace.

$ bundle exec padrino s
bundler: failed to load command: padrino (/home/kimberly/.gem/ruby/3.3.0/bin/padrino)
/home/kimberly/.gem/ruby/3.3.0/bundler/gems/padrino-framework-d75858b05d9c/padrino-core/lib/padrino-core/server.rb:33:in `<module:Padrino>': uninitialized constant Padrino::Rackup (NameError)

  class Server < Rackup::Server
                 ^^^^^^
    from /home/kimberly/.gem/ruby/3.3.0/bundler/gems/padrino-framework-d75858b05d9c/padrino-core/lib/padrino-core/server.rb:1:in `<top (required)>'
    from /home/kimberly/.rubies/ruby-3.3.0/lib/ruby/3.3.0/bundled_gems.rb:74:in `require'
    from /home/kimberly/.rubies/ruby-3.3.0/lib/ruby/3.3.0/bundled_gems.rb:74:in `block (2 levels) in replace_require'
    from /home/kimberly/.gem/ruby/3.3.0/bundler/gems/padrino-framework-d75858b05d9c/padrino-core/lib/padrino-core.rb:15:in `<top (required)>'
    from /home/kimberly/.rubies/ruby-3.3.0/lib/ruby/3.3.0/bundled_gems.rb:74:in `require'
    from /home/kimberly/.rubies/ruby-3.3.0/lib/ruby/3.3.0/bundled_gems.rb:74:in `block (2 levels) in replace_require'
    from /home/kimberly/.gem/ruby/3.3.0/bundler/gems/padrino-framework-d75858b05d9c/padrino/lib/padrino.rb:3:in `<top (required)>'
    from <internal:/home/kimberly/.rubies/ruby-3.3.0/lib/ruby/3.3.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
    from <internal:/home/kimberly/.rubies/ruby-3.3.0/lib/ruby/3.3.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
    from /home/kimberly/.rubies/ruby-3.3.0/lib/ruby/3.3.0/bundled_gems.rb:74:in `block (2 levels) in replace_require'
    from /home/kimberly/.gem/ruby/3.3.0/gems/bundler-2.5.9/lib/bundler/runtime.rb:60:in `block (2 levels) in require'
    from /home/kimberly/.gem/ruby/3.3.0/gems/bundler-2.5.9/lib/bundler/runtime.rb:55:in `each'
    from /home/kimberly/.gem/ruby/3.3.0/gems/bundler-2.5.9/lib/bundler/runtime.rb:55:in `block in require'
    from /home/kimberly/.gem/ruby/3.3.0/gems/bundler-2.5.9/lib/bundler/runtime.rb:44:in `each'
    from /home/kimberly/.gem/ruby/3.3.0/gems/bundler-2.5.9/lib/bundler/runtime.rb:44:in `require'
    from /home/kimberly/.gem/ruby/3.3.0/gems/bundler-2.5.9/lib/bundler.rb:187:in `require'
    from /home/kimberly/.rubies/ruby-3.3.0/lib/ruby/3.3.0/bundled_gems.rb:74:in `require'
    from /home/kimberly/.rubies/ruby-3.3.0/lib/ruby/3.3.0/bundled_gems.rb:74:in `block (2 levels) in replace_require'
    from /home/kimberly/.gem/ruby/3.3.0/bundler/gems/padrino-framework-d75858b05d9c/padrino-core/lib/padrino-core/cli/launcher.rb:25:in `start'
    from /home/kimberly/.gem/ruby/3.3.0/gems/thor-1.3.1/lib/thor/command.rb:28:in `run'
    from /home/kimberly/.gem/ruby/3.3.0/gems/thor-1.3.1/lib/thor/invocation.rb:127:in `invoke_command'
    from /home/kimberly/.gem/ruby/3.3.0/gems/thor-1.3.1/lib/thor.rb:527:in `dispatch'
    from /home/kimberly/.gem/ruby/3.3.0/gems/thor-1.3.1/lib/thor/base.rb:584:in `start'
    from /home/kimberly/.gem/ruby/3.3.0/bundler/gems/padrino-framework-d75858b05d9c/padrino-core/bin/padrino:9:in `<top (required)>'
    from /home/kimberly/.gem/ruby/3.3.0/bin/padrino:25:in `load'
    from /home/kimberly/.gem/ruby/3.3.0/bin/padrino:25:in `<top (required)>'
    from /home/kimberly/.gem/ruby/3.3.0/gems/bundler-2.5.9/lib/bundler/cli/exec.rb:58:in `load'
    from /home/kimberly/.gem/ruby/3.3.0/gems/bundler-2.5.9/lib/bundler/cli/exec.rb:58:in `kernel_load'
    from /home/kimberly/.gem/ruby/3.3.0/gems/bundler-2.5.9/lib/bundler/cli/exec.rb:23:in `run'
    from /home/kimberly/.gem/ruby/3.3.0/gems/bundler-2.5.9/lib/bundler/cli.rb:451:in `exec'
    from /home/kimberly/.gem/ruby/3.3.0/gems/bundler-2.5.9/lib/bundler/vendor/thor/lib/thor/command.rb:28:in `run'
    from /home/kimberly/.gem/ruby/3.3.0/gems/bundler-2.5.9/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
    from /home/kimberly/.gem/ruby/3.3.0/gems/bundler-2.5.9/lib/bundler/vendor/thor/lib/thor.rb:527:in `dispatch'
    from /home/kimberly/.gem/ruby/3.3.0/gems/bundler-2.5.9/lib/bundler/cli.rb:34:in `dispatch'
    from /home/kimberly/.gem/ruby/3.3.0/gems/bundler-2.5.9/lib/bundler/vendor/thor/lib/thor/base.rb:584:in `start'
    from /home/kimberly/.gem/ruby/3.3.0/gems/bundler-2.5.9/lib/bundler/cli.rb:28:in `start'
    from /home/kimberly/.gem/ruby/3.3.0/gems/bundler-2.5.9/exe/bundle:28:in `block in <top (required)>'
    from /home/kimberly/.gem/ruby/3.3.0/gems/bundler-2.5.9/lib/bundler/friendly_errors.rb:117:in `with_friendly_errors'
    from /home/kimberly/.gem/ruby/3.3.0/gems/bundler-2.5.9/exe/bundle:20:in `<top (required)>'
    from /home/kimberly/.rubies/ruby-3.3.0/bin/bundle:25:in `load'
    from /home/kimberly/.rubies/ruby-3.3.0/bin/bundle:25:in `<main>'

What is the expected behavior?

Start the server without errors.

Which versions of Ruby, Padrino, Sinatra, Rack, OS are you using? Did this work in previous versions?

Ruby 3.3.0, Padrino 0.15.3, Ubuntu 23.10.

nesquena commented 7 months ago

@achiurizo would this be fixed with a release from master? Would be great to cut a release that supports Ruby 3.3

kimberlykeilymh commented 7 months ago

Something to mention is that I am using the git repository as a source code, I mean, in my Gemfle it is as follows: gem 'padrino', git: 'https://github.com/padrino/padrino-framework'

achiurizo commented 6 months ago

@kimberlykeilymh thank you for the report! I've pushed out #2289 which should resolve this (adds rackup). If you want to test this sooner, you can try using the branch directly until its merged:

gem 'padrino', git: 'https://github.com/padrino/padrino-framework', branch: 'achiurizo/add-rackup-to-gemspec'

@nesquena we should do more testing after #2289 but after that I think we can go ahead and cut a release

nesquena commented 6 months ago

I went ahead and merged that change. Let us know if that fixes things for you. If everything is working as expected, we can do final testing and cut a release

kimberlykeilymh commented 6 months ago

Thanks guys! The change fixed the bug with rackup.

Although now I get this other error:

bundler: failed to load command: padrino (/home/kimberly/.gem/ruby/3.3.0/bin/padrino)
/home/kimberly/.gem/ruby/3.3.0/bundler/gems/padrino-framework-889f6623c071/padrino-core/lib/padrino-core/server.rb:24:in `detect_application': undefined method `merge' for nil (NoMethodError)

      [rack_app, rack_options.merge(options)]
                             ^^^^^^
    from /home/kimberly/.gem/ruby/3.3.0/bundler/gems/padrino-framework-889f6623c071/padrino-core/lib/padrino-core/server.rb:12:in `run!'
    from /home/kimberly/.gem/ruby/3.3.0/bundler/gems/padrino-framework-889f6623c071/padrino-core/lib/padrino-core/cli/adapter.rb:9:in `start'
    from /home/kimberly/.gem/ruby/3.3.0/bundler/gems/padrino-framework-889f6623c071/padrino-core/lib/padrino-core/cli/launcher.rb:30:in `start'
    from /home/kimberly/.gem/ruby/3.3.0/gems/thor-1.3.1/lib/thor/command.rb:28:in `run'
    from /home/kimberly/.gem/ruby/3.3.0/gems/thor-1.3.1/lib/thor/invocation.rb:127:in `invoke_command'
    from /home/kimberly/.gem/ruby/3.3.0/gems/thor-1.3.1/lib/thor.rb:527:in `dispatch'
    from /home/kimberly/.gem/ruby/3.3.0/gems/thor-1.3.1/lib/thor/base.rb:584:in `start'
    from /home/kimberly/.gem/ruby/3.3.0/bundler/gems/padrino-framework-889f6623c071/padrino-core/bin/padrino:9:in `<top (required)>'
    from /home/kimberly/.gem/ruby/3.3.0/bin/padrino:25:in `load'
    from /home/kimberly/.gem/ruby/3.3.0/bin/padrino:25:in `<top (required)>'
    from /home/kimberly/.gem/ruby/3.3.0/gems/bundler-2.5.9/lib/bundler/cli/exec.rb:58:in `load'
    from /home/kimberly/.gem/ruby/3.3.0/gems/bundler-2.5.9/lib/bundler/cli/exec.rb:58:in `kernel_load'
    from /home/kimberly/.gem/ruby/3.3.0/gems/bundler-2.5.9/lib/bundler/cli/exec.rb:23:in `run'
    from /home/kimberly/.gem/ruby/3.3.0/gems/bundler-2.5.9/lib/bundler/cli.rb:451:in `exec'
    from /home/kimberly/.gem/ruby/3.3.0/gems/bundler-2.5.9/lib/bundler/vendor/thor/lib/thor/command.rb:28:in `run'
    from /home/kimberly/.gem/ruby/3.3.0/gems/bundler-2.5.9/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
    from /home/kimberly/.gem/ruby/3.3.0/gems/bundler-2.5.9/lib/bundler/vendor/thor/lib/thor.rb:527:in `dispatch'
    from /home/kimberly/.gem/ruby/3.3.0/gems/bundler-2.5.9/lib/bundler/cli.rb:34:in `dispatch'
    from /home/kimberly/.gem/ruby/3.3.0/gems/bundler-2.5.9/lib/bundler/vendor/thor/lib/thor/base.rb:584:in `start'
    from /home/kimberly/.gem/ruby/3.3.0/gems/bundler-2.5.9/lib/bundler/cli.rb:28:in `start'
    from /home/kimberly/.gem/ruby/3.3.0/gems/bundler-2.5.9/exe/bundle:28:in `block in <top (required)>'
    from /home/kimberly/.gem/ruby/3.3.0/gems/bundler-2.5.9/lib/bundler/friendly_errors.rb:117:in `with_friendly_errors'
    from /home/kimberly/.gem/ruby/3.3.0/gems/bundler-2.5.9/exe/bundle:20:in `<top (required)>'
    from /home/kimberly/.gem/ruby/3.3.0/bin/bundle:25:in `load'
    from /home/kimberly/.gem/ruby/3.3.0/bin/bundle:25:in `<main>'

Is it also possible to check this error? I can open another issue and close this one if you want.

nesquena commented 6 months ago

@achiurizo hmm, looks like rack_options is nil rather than a hash now in the server start sequence

srolandmarshall commented 6 months ago

@nesquena I built a Padrino app from scratch with limited changes to config (updating database) — using Edge release w/ the inclusion of Backup in the Gemspec results in the issue @kimberlykeilymh mentioned above.

➜  probable-pitchers-padrino git:(main) padrino start
/Users/sam-home/.rvm/gems/ruby-3.1.3/bundler/gems/padrino-framework-889f6623c071/padrino-core/lib/padrino-core/server.rb:24:in `detect_application': undefined method `merge' for nil:NilClass (NoMethodError)

      [rack_app, rack_options.merge(options)]
                             ^^^^^^
        from /Users/sam-home/.rvm/gems/ruby-3.1.3/bundler/gems/padrino-framework-889f6623c071/padrino-core/lib/padrino-core/server.rb:12:in `run!'

Prior to using the Edge release, I was using the default release and included Backup using bundler add rackup to the same issue

nesquena commented 6 months ago

As a starting point, thanks @srolandmarshall I don't want to be too optimistic but it seems like part of this may just be a change to the way Rack parses the files. I had rack options default to {} on https://github.com/padrino/padrino-framework/pull/2290 (branch nesquena-rack-options-fix) until achiu may have a chance to test end to end

It's possible this would fix it, but also possible and likely there's larger changes to Rack that need to be adjusted in the core server startup sequence

srolandmarshall commented 6 months ago

Checked it out, seemed to solve the problem on my end. Thanks for the quick patch @nesquena

nesquena commented 6 months ago

Great, thanks for testing! @achiurizo can you merge my PR, and @kimberlykeilymh can you try my patch as well and report back either now or after we merge to master

kimberlykeilymh commented 6 months ago

Hi guys! Yes, that solved the problem and padrino is running without errors. Thanks very much for the fix!

nesquena commented 6 months ago

That's great news, thanks for testing! Since two of you confirmed, perhaps it's time to cut a new release soon

floriandejonckheere commented 3 months ago

Hi! Any news on a new release of Padrino?

nesquena commented 3 months ago

I'll push out a new release with these fixes within a week

nesquena commented 3 months ago

Okay I pushed out release 0.16.0.pre2 which appears compatible with latest Rack and Ruby - can one or two of you try this and report back confirming everything works as it should?

@floriandejonckheere @achiurizo @kimberlykeilymh @srolandmarshall

As soon as I get confirmations, I'll cut it as an official release! If anyone wants to help fix the CI to pass the tests fully, that would be appreciated as well 😅

kimberlykeilymh commented 3 months ago

Hi folks! Thanks for pushed out a new version! I try the pre-release version with Ruby 3.3.0, but I got this error:

bundler: failed to load command: padrino (/home/kimberly/.gem/ruby/3.3.0/bin/padrino)
/home/kimberly/.gem/ruby/3.3.0/gems/padrino-core-0.16.0.pre2/lib/padrino-core/server.rb:86:in `detect_rack_handler': Server handler (thin, puma, spider-gazelle, mongrel, trinidad, webrick) not found. (RuntimeError)
    from /home/kimberly/.gem/ruby/3.3.0/gems/padrino-core-0.16.0.pre2/lib/padrino-core/server.rb:45:in `start'
    from /home/kimberly/.gem/ruby/3.3.0/gems/padrino-core-0.16.0.pre2/lib/padrino-core/server.rb:12:in `run!'
    from /home/kimberly/.gem/ruby/3.3.0/gems/padrino-core-0.16.0.pre2/lib/padrino-core/cli/adapter.rb:9:in `start'
    from /home/kimberly/.gem/ruby/3.3.0/gems/padrino-core-0.16.0.pre2/lib/padrino-core/cli/launcher.rb:30:in `start'
    from /home/kimberly/.gem/ruby/3.3.0/gems/thor-1.3.1/lib/thor/command.rb:28:in `run'
    from /home/kimberly/.gem/ruby/3.3.0/gems/thor-1.3.1/lib/thor/invocation.rb:127:in `invoke_command'
    from /home/kimberly/.gem/ruby/3.3.0/gems/thor-1.3.1/lib/thor.rb:527:in `dispatch'
    from /home/kimberly/.gem/ruby/3.3.0/gems/thor-1.3.1/lib/thor/base.rb:584:in `start'
    from /home/kimberly/.gem/ruby/3.3.0/gems/padrino-core-0.16.0.pre2/bin/padrino:9:in `<top (required)>'
    from /home/kimberly/.gem/ruby/3.3.0/bin/padrino:25:in `load'
    from /home/kimberly/.gem/ruby/3.3.0/bin/padrino:25:in `<top (required)>'
    from /home/kimberly/.gem/ruby/3.3.0/gems/bundler-2.5.17/lib/bundler/cli/exec.rb:58:in `load'
    from /home/kimberly/.gem/ruby/3.3.0/gems/bundler-2.5.17/lib/bundler/cli/exec.rb:58:in `kernel_load'
    from /home/kimberly/.gem/ruby/3.3.0/gems/bundler-2.5.17/lib/bundler/cli/exec.rb:23:in `run'
    from /home/kimberly/.gem/ruby/3.3.0/gems/bundler-2.5.17/lib/bundler/cli.rb:455:in `exec'
    from /home/kimberly/.gem/ruby/3.3.0/gems/bundler-2.5.17/lib/bundler/vendor/thor/lib/thor/command.rb:28:in `run'
    from /home/kimberly/.gem/ruby/3.3.0/gems/bundler-2.5.17/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
    from /home/kimberly/.gem/ruby/3.3.0/gems/bundler-2.5.17/lib/bundler/vendor/thor/lib/thor.rb:527:in `dispatch'
    from /home/kimberly/.gem/ruby/3.3.0/gems/bundler-2.5.17/lib/bundler/cli.rb:35:in `dispatch'
    from /home/kimberly/.gem/ruby/3.3.0/gems/bundler-2.5.17/lib/bundler/vendor/thor/lib/thor/base.rb:584:in `start'
    from /home/kimberly/.gem/ruby/3.3.0/gems/bundler-2.5.17/lib/bundler/cli.rb:29:in `start'
    from /home/kimberly/.gem/ruby/3.3.0/gems/bundler-2.5.17/exe/bundle:28:in `block in <top (required)>'
    from /home/kimberly/.gem/ruby/3.3.0/gems/bundler-2.5.17/lib/bundler/friendly_errors.rb:117:in `with_friendly_errors'
    from /home/kimberly/.gem/ruby/3.3.0/gems/bundler-2.5.17/exe/bundle:20:in `<top (required)>'
    from /home/kimberly/.gem/ruby/3.3.0/bin/bundle:25:in `load'
    from /home/kimberly/.gem/ruby/3.3.0/bin/bundle:25:in `<main>'
nesquena commented 3 months ago

Based on this part of the error:

Server handler (thin, puma, spider-gazelle, mongrel, trinidad, webrick) not found.

I wonder if you could try adding the "puma" gem or thin to the Gemfile of your app, run bundle and then try starting it up again?

Does that change anything?

kimberlykeilymh commented 3 months ago

Something I forgot to mention is that we use WEBrick as a server, which is part of the server list.

kimberlykeilymh commented 3 months ago

Trying with Puma and thin I got the same error

nesquena commented 3 months ago

Thanks @kimberlykeilymh for testing! I'm glad I did this as a pre release 😅

And once we figure out this issue, get all the tests passing, and confirm things are looking good, I'll push an official version

nesquena commented 3 months ago

@achiurizo Any idea what might be going on above?

osbre commented 3 months ago

@nesquena I have found the cause and sent a fix: https://github.com/padrino/padrino-framework/pull/2294

Can confirm it now works with Puma.

nesquena commented 3 months ago

@nesquena I have found the cause and sent a fix: https://github.com/padrino/padrino-framework/pull/2294

Can confirm it now works with Puma.

Thank you! 🙏 I'll release pre3 today with this fix so others can confirm

nesquena commented 3 months ago

Pushed pre3

@kimberlykeilymh Can you try again with the latest pre3 release and confirm that everything works as expected now?

kimberlykeilymh commented 3 months ago

Hi Nathan! @nesquena I tested the pre3 version and the error with the server no longer occurs, thank you very much for fixing it!

On the other hand, I had an error with this new version regarding the parameters received by the controller. In one of the forms we have fields nested in two levels that reach the controller in the following way:

(ruby) params
{
     "account"=>
     {
          "status"=>"active",
          "account_settings"=>
          {
               "example_field"=>"example_value"
          },
          "name"=>"Account Name"
     } 
}

But now those same parameters are obtained like this:

(ruby) params
{
     "account"=>
     {
          "status"=>"active",
          "account_settings[example_field"=>
          {
               "]"=>"example_value"
          },
          "name"=>"Account Name"
     } 
}

At the form level the name of the fields remains the same (account[account_settings[example_field]]).

This would be for example for an Account model, which is associated with an AccountSettings model which has an example_field field.

Do you have any idea what could be happening? Is there some new definition in the framework that does not allow nesting in more than one level?

Thanks in advance,

nesquena commented 3 months ago

Thanks so much for testing @kimberlykeilymh and catching the issue with nested form parameter processing. That seems like a bug. Before we release, we'll fix this so that it matches the original behavior

If anyone can help investigate, and or write tests for this, or fix any other failing tests, that would be appreciated

Before this next major release, we'll also need to fix all failing tests and test a number of apps work as expected. But glad we are making some progress 😊

rasheqrahman commented 1 month ago

Building on @kimberlykeilymh's issue, here's what I'm getting when I try to deploy to heroku running Ruby 3.2.5

NameError: uninitialized constant Rack::Server (NameError)

class Server < Rack::Server ^^^^^^^^ Did you mean? TCPServer /Users/rasheqrahman/.rvm/gems/ruby-3.2.5/gems/padrino-core-0.15.3/lib/padrino-core/server.rb:34:in <module:Padrino>' /Users/rasheqrahman/.rvm/gems/ruby-3.2.5/gems/padrino-core-0.15.3/lib/padrino-core/server.rb:1:in<top (required)>' <internal:/Users/rasheqrahman/.rvm/rubies/ruby-3.2.5/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:38:in require' <internal:/Users/rasheqrahman/.rvm/rubies/ruby-3.2.5/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:38:inrequire' /Users/rasheqrahman/.rvm/gems/ruby-3.2.5/gems/padrino-core-0.15.3/lib/padrino-core.rb:15:in <top (required)>' <internal:/Users/rasheqrahman/.rvm/rubies/ruby-3.2.5/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:38:inrequire' <internal:/Users/rasheqrahman/.rvm/rubies/ruby-3.2.5/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:38:in require' /Users/rasheqrahman/wikiidea/Rakefile:4:in<top (required)>' /Users/rasheqrahman/.rvm/gems/ruby-3.2.5/gems/rake-13.2.1/exe/rake:27:in <top (required)>' /Users/rasheqrahman/.rvm/gems/ruby-3.2.5/bin/ruby_executable_hooks:22:ineval' /Users/rasheqrahman/.rvm/gems/ruby-3.2.5/bin/ruby_executable_hooks:22:in `

' (See full trace by running task with --trace)

rasheqrahman commented 1 month ago

Can anyone help? I and ChatGPT are at a loss on how to fix this. I've just been trying to update my sinatra/padrino app to run on the latest heroku stack which runs 3.2.5

rasheqrahman commented 1 month ago

I definitely keep getting the same error and I'm stuck.

/Users/rasheqrahman/.rvm/gems/ruby-3.2.5/gems/padrino-core-0.15.3/lib/padrino-core/server.rb:34:in `': uninitialized constant Rack::Server (NameError)

class Server < Rack::Server ^^^^^^^^ Did you mean? TCPServer from /Users/rasheqrahman/.rvm/gems/ruby-3.2.5/gems/padrino-core-0.15.3/lib/padrino-core/server.rb:1:in <top (required)>' from <internal:/Users/rasheqrahman/.rvm/rubies/ruby-3.2.5/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:38:inrequire' from <internal:/Users/rasheqrahman/.rvm/rubies/ruby-3.2.5/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:38:in require' from /Users/rasheqrahman/.rvm/gems/ruby-3.2.5/gems/padrino-core-0.15.3/lib/padrino-core.rb:15:in<top (required)>' from <internal:/Users/rasheqrahman/.rvm/rubies/ruby-3.2.5/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:38:in require' from <internal:/Users/rasheqrahman/.rvm/rubies/ruby-3.2.5/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:38:inrequire' from /Users/rasheqrahman/.rvm/gems/ruby-3.2.5/gems/padrino-0.15.3/lib/padrino.rb:3:in <top (required)>' from /Users/rasheqrahman/.rvm/gems/ruby-3.2.5/gems/bundler-2.5.21/lib/bundler/runtime.rb:60:inrequire' from /Users/rasheqrahman/.rvm/gems/ruby-3.2.5/gems/bundler-2.5.21/lib/bundler/runtime.rb:60:in block (2 levels) in require' from /Users/rasheqrahman/.rvm/gems/ruby-3.2.5/gems/bundler-2.5.21/lib/bundler/runtime.rb:55:ineach' from /Users/rasheqrahman/.rvm/gems/ruby-3.2.5/gems/bundler-2.5.21/lib/bundler/runtime.rb:55:in block in require' from /Users/rasheqrahman/.rvm/gems/ruby-3.2.5/gems/bundler-2.5.21/lib/bundler/runtime.rb:44:ineach' from /Users/rasheqrahman/.rvm/gems/ruby-3.2.5/gems/bundler-2.5.21/lib/bundler/runtime.rb:44:in require' from /Users/rasheqrahman/.rvm/gems/ruby-3.2.5/gems/bundler-2.5.21/lib/bundler.rb:212:inrequire' from /Users/rasheqrahman/wikiidea/config/boot.rb:14:in <top (required)>' from <internal:/Users/rasheqrahman/.rvm/rubies/ruby-3.2.5/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:38:inrequire' from <internal:/Users/rasheqrahman/.rvm/rubies/ruby-3.2.5/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:38:in require' from /Users/rasheqrahman/.rvm/gems/ruby-3.2.5/gems/padrino-core-0.15.3/lib/padrino-core/cli/launcher.rb:25:instart' from /Users/rasheqrahman/.rvm/gems/ruby-3.2.5/gems/thor-1.3.2/lib/thor/command.rb:28:in run' from /Users/rasheqrahman/.rvm/gems/ruby-3.2.5/gems/thor-1.3.2/lib/thor/invocation.rb:127:ininvoke_command' from /Users/rasheqrahman/.rvm/gems/ruby-3.2.5/gems/thor-1.3.2/lib/thor.rb:538:in dispatch' from /Users/rasheqrahman/.rvm/gems/ruby-3.2.5/gems/thor-1.3.2/lib/thor/base.rb:584:instart' from /Users/rasheqrahman/.rvm/gems/ruby-3.2.5/gems/padrino-core-0.15.3/bin/padrino:9:in <top (required)>' from /Users/rasheqrahman/.rvm/gems/ruby-3.2.5/bin/padrino:25:inload' from /Users/rasheqrahman/.rvm/gems/ruby-3.2.5/bin/padrino:25:in <main>' from /Users/rasheqrahman/.rvm/gems/ruby-3.2.5/bin/ruby_executable_hooks:22:ineval' from /Users/rasheqrahman/.rvm/gems/ruby-3.2.5/bin/ruby_executable_hooks:22:in `

'

chaymaeBZ commented 1 week ago

@rasheqrahman you are using padrino 0.15.3 and as discussed here, 0.16.0.pre3 should fix uninitialized constant Rack::Server (NameError) and introduces support to ruby 3.2.

chaymaeBZ commented 5 days ago

Hi @kimberlykeilymh :wave: I am not able to replicate the error you are seeing with nested models. I created a dummy app with Padrino 0.16.0.pre3 version with nested models and forms. However, I am receiving the nested params in the correct way. Could it be something with the form helpers you are using? I used form_for for the parent model and fields_for for the nested model. Could you share a snippet of your forms?

nesquena commented 5 days ago

Thanks for testing this @chaymaeBZ 🙏 , and I'll be happy to release the next version in full outside of pre once we feel confident tests are passing again and that all critical bugs have been worked out. I haven't had time unfortunately to dig deep into the nested forms issue yet, I wasn't able to reproduce with a simple nested example, but perhaps it's like second layer nesting where it's failing?

chaymaeBZ commented 4 days ago

Thanks @nesquena! indeed I could replicate this!

I wrote simple steps to reproduce it :

$ padrino g project nested_params_example $ echo "gem 'puma'" >> Gemfile ( Also Make sure padrino version is 0.16.0.pre3 in the Gemfile) $ bundle exec padrino g controller example Edit the example controller :

NestedParamsExample::App.controllers :example do
  post :submit do
    "params received: #{params.inspect}"
  end
end

(remove csrf protection from config/apps.rb or set it to false)

$ bundle exec padrino s $ curl -X POST http://127.0.0.1:3000/example/submit -d "account[account_settings[example_field]]=value" returns : # => params received: {"account"=>{"account_settings[example_field"=>{"]"=>"value"}}}

nesquena commented 4 days ago

Thank you, that is really helpful, this may be one of the last major issues before we can release the new version. If anyone has a chance to review and put in a fix for this nested form parsing issue, I'd be happy to review and merge and cut a release once kimberly confirms the fix. I'll try to find time to fix it myself eventually. Also any work to fix broken tests is appreciated too

Thanks to everyone for your help

chaymaeBZ commented 4 days ago

I did a deep dive into this. As I suspected, this has nothing to do with Padrino. This behavior comes from Rack. And this change was introduced in Rack 3. You can try the same workflow with Sinatra 4 and it will yield the same 'weird' result.

Now this not a bug. In fact, it's only weird to set nested params as account[account_settings[example_field]]=value, even though this was tolerated before. You can even set nested params as account[account_settings]example_field=value and it will work just fine.

The recommended way to send your nested fields is to use account[account_settings][example_field]=value. In fact, this is what the form builders are doing to build nested fields. it sets the name to account[account_settings][example_field]=value.

You can try it, switching between rack 2 and rack 3

# rack 3
Rack::Utils.parse_nested_query "account[account_settings[example_field]]=value"
#=> {"account"=>{"account_settings[example_field"=>{"]"=>"value"}}}

# rack 2
Rack::Utils.parse_nested_query "account[account_settings[example_field]]=value"
#=> {"account"=>{"account_settings"=>{"example_field"=>"value"}}}

Rack::Utils.parse_nested_query "account[account_settings]example_field=value"
#=> {"account"=>{"account_settings"=>{"example_field"=>"value"}}}

The change has been introduced here, where it tries to "scan" for what's between [ and ] to set the nested key.

Here is another way to test this behavior of rack

require 'stringio'
require 'rack'

def get_params(input)
    rack_input = StringIO.new(input)

    env = {'rack.input' => rack_input, 'REQUEST_METHOD' => 'POST'}
    request = Rack::Request.new(env)

    request.params
end

correct_input = "account[account_settings][example_field]=value"
wrong_input = "account[account_settings[example_field]]=value"

p get_params(correct_input)
# => Rack 2 :
# => {"account"=>{"account_settings"=>{"example_field"=>"value"}}}

# => Rack 3 :
# => {"account"=>{"account_settings"=>{"example_field"=>"value"}}}

p get_params(wrong_input)
# => Rack 2 :
# => {"account"=>{"account_settings"=>{"example_field"=>"value"}}}

# => Rack 3 :
# => {"account"=>{"account_settings[example_field"=>{"]"=>"value"}}}
nesquena commented 4 days ago

I see, is it possible then that this is more of a won't fix? It may not be our responsibility to address this unless our own form helpers are generating incorrect code. What's your recommendation?

AFAIK this may be the last known issue before I can cut a release.

chaymaeBZ commented 3 days ago

I'd say it's a won't fix thing. I wouldn't even call it a bug 😂 A[B][C] is how you do nesting, not A[B[C]].

I tried with the form generators, it's not generating such weird nesting syntax. So I'd say it's up to people to fix any weird nesting syntax they hardcoded.

chaymaeBZ commented 3 days ago

@kimberlykeilymh can you share a snippet of your form?

kimberlykeilymh commented 9 hours ago

Hello everyone! Thank you for taking the time to review the potential error. I’m sharing a snippet of the original form and a modified one for testing (along with their results):

= form_for @account, url_for(:accounts, :index, id: @account.id), method: :put do |f|
      .form-group.row
        = f.label 'account_settings[ex_integration_enabled]', caption: 'Integración EX', class: ['col-form-label', 'col-lg-2']
        = f.check_box 'account_settings[ex_integration_enabled]', class: ['form-control', 'custom-control-input'], checked: !@account.account_settings&.value&.[]('ex_integration_enabled').nil?

(ruby) params[:account]
{"account_settings[mp_integration_enabled"=>{"]"=>"1"}}
= form_for @account, url_for(:accounts, :index, id: @account.id), method: :put do |f|
      .form-group.row
        = f.label 'account_settings[ex_integration_enabled]', caption: 'Integración EX', class: ['col-form-label', 'col-lg-2']
            = f.check_box '[account_settings][ex_integration_enabled]', class: ['form-control', 'custom-control-input'], checked: !@account.account_settings&.value&.[]('ex_integration_enabled').nil?

(ruby) params[:account]
{"[account_settings"=>{"mp_integration_enabled"=>{"]"=>"1"}}}
chaymaeBZ commented 8 hours ago

@kimberlykeilymh you are using the form builders in a wrong way. If you inspect both forms, the first checkbox's name will look something like account[account_settings[ex_integration_enabled]] and the second will look like account[[account_settings][ex_integration_enabled]]. As I explained earlier, this is wrong nesting syntax. please use fields_for to build your nested forms. Or read the docs for alternatives https://padrinorb.com/guides/application-helpers/nested-object-form-support/

nesquena commented 7 hours ago

Thanks @chaymaeBZ for investigating this! @kimberlykeilymh can you try to make those adjustments to the form helpers and confirm everything works as expected, test around and give me confirmation that nothing appears broken?