Skip to content

Fix: symfony_console should not re-scope hosts, caller already provides on block - #127

Open
ahmed-bhs wants to merge 1 commit into
capistrano:masterfrom
ahmed-bhs:fix/symfony-console-ignores-caller-role
Open

Fix: symfony_console should not re-scope hosts, caller already provides on block#127
ahmed-bhs wants to merge 1 commit into
capistrano:masterfrom
ahmed-bhs:fix/symfony-console-ignores-caller-role

Conversation

@ahmed-bhs

Copy link
Copy Markdown

Fixes #126

Problem

symfony_console always wraps its execute in its own on release_roles(fetch(:symfony_deploy_roles)) block. Every caller in lib/capistrano/tasks/symfony.rake already calls symfony_console from inside its own on release_roles(...) block with a caller-chosen role. Because SSHKit's on has no shared "current backend" state, the inner on inside symfony_console silently ignores the outer scope and re-resolves hosts from symfony_deploy_roles instead.

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 :role mechanism.

Fix

Remove the inner on/release_roles wrapping from symfony_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:install all already call it from inside their own on block).

Compatibility

No caller of symfony_console in this gem calls it outside of an on block, so this is not a breaking change for the gem's own tasks. Projects calling symfony_console directly outside of an on block (undocumented usage) would need to wrap the call in on roles(...) do ... end themselves — which is the documented/intended way to use SSHKit's execute.

…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

symfony_console ignores caller-supplied role/host scope, always uses symfony_deploy_roles

1 participant