Skip to content

Fix: Add Symfony Console 7.4+ addCommand() compatibility#1185

Open
laetus007 wants to merge 2 commits into
consolidation:5.xfrom
laetus007:5.x
Open

Fix: Add Symfony Console 7.4+ addCommand() compatibility#1185
laetus007 wants to merge 2 commits into
consolidation:5.xfrom
laetus007:5.x

Conversation

@laetus007

@laetus007 laetus007 commented Jan 12, 2026

Copy link
Copy Markdown

Overview

This pull request:

  • Fixes a bug
  • Adds a feature
  • Breaks backwards compatibility
  • Has tests that cover changes
  • Adds or fixes documentation

Summary

Proposed Solution:
Added a compatibility wrapper addCommand() in Robo\Application that:

  • Calls parent::addCommand() if available (Symfony 7.4+)
  • Falls back to parent::add() for Symfony 6
  • Override add() in Robo\Application to redirect to addCommand()

Update all internal calls to use addCommand() instead of add()

This ensures Robo works without deprecation warnings on Symfony 7.4+ and remains compatible with Symfony 6.

Description

When using Robo with Symfony Console 7.4+, a deprecation warning is triggered:

ERROR: Since symfony/console 7.4: The "Symfony\Component\Console\Application::add()" method is deprecated and will be removed in Symfony 8.0, use "Symfony\Component\Console\Application::addCommand()" instead.

This occurs because Robo and its consumers call add() to register commands, but Symfony 7.4+ expects addCommand() instead. However, Symfony 6 does not have addCommand(), so a compatibility layer is needed.

***Note: We heavily use robo to orchestrate our local development and CI/CD for a single Drupal codebase using a custom upstream in Pantheon for over 200+ sites. We recently updated to Drupal 11.3 and we started getting a number of errors when running the custom robo commands. AI was used in the analysis of this issue and the solution proposed. We have tested against our own codebase and validated the errors no longer appear for us. I'll watch this to see if there are any test failures and will try to gracefully address, if possible and as time permits.

@pixelbrackets

pixelbrackets commented Feb 5, 2026

Copy link
Copy Markdown
Contributor

I tested this in issue 1183, works like a charm. All breaking messages gone. A merge would be appreciated since this affects every run of a robo script.

@vworldat

Copy link
Copy Markdown

@greg-1-anderson any chance to get this merged and released soon? It's a real bummer ATM 🫤

@apotek apotek left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks complete, and I like the compatibility wrapper with a clear instruction as to how to fix the invalid argument.

This solves a current issue with Robo. I see no reason to hold it back. Thank you aetus007

Update: Tested on several projects using Robo and works flawlessly.

@andypost

andypost commented Mar 19, 2026

Copy link
Copy Markdown
Contributor

it looks like better to add the shim to annotated command repo so robo and config and drush can reuse it

faced working on Symfon7 8+ compatibility where the add() method is removed #1187

@laetus007

Copy link
Copy Markdown
Author

Yes - I agree that this should not be merged here and it is more appropriate to address - https://github.com/search?q=repo%3Aconsolidation%2Fannotated-command+-%3Eadd%28&type=code

What is best practice in this scenario? Convert this to draft while the issue is reported and addressed in the annotated-command?

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.

5 participants