You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello! I've been testing the wonderful debug gem with the GitHub monolith. I noticed an issue using it with autoloading that makes me concerned it's not fully compatible with zeitwerk: autoloading some constants fail inside a debugger session when they do not in a normal context. This looks similar to how byebug fails with zeitwerk, see fxn/zeitwerk#31 (comment) and deivid-rodriguez/byebug#564 although I imagine it might be a different underlying cause.
open a debugger session with bin/rails runner debugger
Reference Git::Ref::Collection in the debugger by typing it.
(Optional) verify that the constant loads correctly in a normal console.
In case something happens to my test repo, here are the test files:
$ tree git/
git/
├── ref
│ ├── collection
│ │ └── pagination.rb
│ └── collection.rb
└── ref.rb
$ cat git/ref.rb
# frozen_string_literal: true
module Git
class Ref
end
end
$ cat git/ref/collection.rb
# frozen_string_literal: true
class Git::Ref::Collection
end
$ cat git/ref/collection/pagination.rb
# frozen_string_literal: true
module Git::Ref::Collection::Pagination
end
Expected behavior
All constants that can autoload outside a debugger session also load within one. In particular referencing Git::Ref::Collection in the above example when it is not loaded should autoload it.
Actual behavior
Referencing Git::Ref::Collection inside a debugger session triggers uninitialized constant Git::Ref::Collection, although the same behavior outside a debugger session works fine.
Additional details
This repro was extracted from real files in the github monolith. In case it helps, here are the zeitwerk debug logs emitted when debug and an IRB session attempt to load this constant:
debug (started from IRB):
(rdbg) Git::Ref::Collection
Zeitwerk@rails.main: module Git autovivified from directory app/models/git
Zeitwerk@rails.main: autoload set for Git::Ref, to be autovivified from app/models/git/ref
Zeitwerk@rails.main: earlier autoload for Git::Ref discarded, it is actually an explicit namespace defined in app/models/git/ref.rb
Zeitwerk@rails.main: autoload set for Git::Ref, to be loaded from app/models/git/ref.rb
Zeitwerk@rails.main: constant Git::Ref loaded from file app/models/git/ref.rb
eval error: uninitialized constant Git::Ref::Collection
(rdbg)(irb):1: in `<main>'
IRB: (started using bin/rails console):
irb(main):001:0> Git::Ref::Collection
Zeitwerk@rails.main: module Git autovivified from directory app/models/git
Zeitwerk@rails.main: autoload set for Git::Ref, to be autovivified from app/models/git/ref
Zeitwerk@rails.main: earlier autoload for Git::Ref discarded, it is actually an explicit namespace defined in app/models/git/ref.rb
Zeitwerk@rails.main: autoload set for Git::Ref, to be loaded from app/models/git/ref.rb
Zeitwerk@rails.main: autoload set for Git::Ref::Collection, to be autovivified from app/models/git/ref/collection
Zeitwerk@rails.main: earlier autoload for Git::Ref::Collection discarded, it is actually an explicit namespace defined in app/models/git/ref/collection.rb
Zeitwerk@rails.main: autoload set for Git::Ref::Collection, to be loaded from app/models/git/ref/collection.rb
Zeitwerk@rails.main: constant Git::Ref loaded from file app/models/git/ref.rb
Zeitwerk@rails.main: autoload set for Git::Ref::Collection::Pagination, to be loaded from app/models/git/ref/collection/pagination.rb
Zeitwerk@rails.main: constant Git::Ref::Collection loaded from file app/models/git/ref/collection.rb
=> Git::Ref::Collection
Hello! I've been testing the wonderful debug gem with the GitHub monolith. I noticed an issue using it with autoloading that makes me concerned it's not fully compatible with zeitwerk: autoloading some constants fail inside a debugger session when they do not in a normal context. This looks similar to how byebug fails with zeitwerk, see fxn/zeitwerk#31 (comment) and deivid-rodriguez/byebug#564 although I imagine it might be a different underlying cause.
It's difficult to use the bug report tempate to explain this issue so I've opened https://github.com/brasic/rails-debug-bug-report to demonstrate the issue.
/cc @fxn @ko1 @jhawthorn
Steps to reproduce
bundle exec railties/exe/rails new ../myapp --edge --dev
)app/models
: brasic/rails-debug-bug-report@7b64856bin/rails runner debugger
Git::Ref::Collection
in the debugger by typing it.In case something happens to my test repo, here are the test files:
Expected behavior
All constants that can autoload outside a debugger session also load within one. In particular referencing
Git::Ref::Collection
in the above example when it is not loaded should autoload it.Actual behavior
Referencing
Git::Ref::Collection
inside a debugger session triggersuninitialized constant Git::Ref::Collection
, although the same behavior outside a debugger session works fine.Additional details
This repro was extracted from real files in the github monolith. In case it helps, here are the zeitwerk debug logs emitted when debug and an IRB session attempt to load this constant:
debug (started from IRB):
IRB: (started using
bin/rails console
):System configuration
Rails version: tested on 6e16942, 6e83d06
Ruby version: tested on
3.0.2p107
,3.0.3p143 (2021-10-09 revision fe6d90fd66)
The text was updated successfully, but these errors were encountered: