Fix: symfony_console should not re-scope hosts, caller already provides on block - #127
Open
ahmed-bhs wants to merge 1 commit into
Open
Conversation
…es on block symfony_console always wraps execute in its own `on release_roles(fetch(:symfony_deploy_roles))`, hardcoded to :symfony_deploy_roles (defaults to :all). Every caller in lib/capistrano/tasks/symfony.rake already invokes symfony_console from inside its own on release_roles(...) block using a caller-supplied role (e.g. symfony:console's :role arg, or a custom symfony_doctrine_migrate_roles-style variable in a project's own tasks). Because SSHKit's on just spins up an independent Coordinator per call, the nested on inside symfony_console silently ignores the outer scope and re-resolves hosts from symfony_deploy_roles, so any command run through symfony_console executes on symfony_deploy_roles's hosts instead of the role the caller intended. Concretely this means a project cannot scope a migration (or any other symfony:console-based task) to a subset of hosts (e.g. a single :db host) by passing a role/host list to the outer on block or to symfony:console's :role argument: it will still run everywhere symfony_deploy_roles resolves to. Removing the inner on/release_roles call from symfony_console makes it run in whatever host context it was already called from, matching how every task in this gem already uses it. See capistrano#90 for a related report of the same symfony_deploy_roles vs symfony_roles inconsistency.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #126
Problem
symfony_consolealways wraps itsexecutein its ownon release_roles(fetch(:symfony_deploy_roles))block. Every caller inlib/capistrano/tasks/symfony.rakealready callssymfony_consolefrom inside its ownon release_roles(...)block with a caller-chosen role. Because SSHKit'sonhas no shared "current backend" state, the inneroninsidesymfony_consolesilently ignores the outer scope and re-resolves hosts fromsymfony_deploy_rolesinstead.This makes it impossible for a project to scope a
symfony:console-based command to a subset of hosts (e.g. run a Doctrine migration once, only on a primary/db host) via the existing:rolemechanism.Fix
Remove the inner
on/release_roleswrapping fromsymfony_console. It now just executes in whatever host context it was already called from — which matches every existing call site in this gem (symfony:console,symfony:cache:clear,symfony:cache:warmup,symfony:assets:installall already call it from inside their ownonblock).Compatibility
No caller of
symfony_consolein this gem calls it outside of anonblock, so this is not a breaking change for the gem's own tasks. Projects callingsymfony_consoledirectly outside of anonblock (undocumented usage) would need to wrap the call inon roles(...) do ... endthemselves — which is the documented/intended way to use SSHKit'sexecute.