doctrine/orm · error · InvalidArgumentException
Invalid argument "--entity-class"
Error message
Invalid argument "--entity-class"
What it means
orm:clear-cache:region:entity evicts the second-level cache region of one entity class. Without an entity-class argument and without --all, there is no region to target, so the command throws InvalidArgumentException('Invalid argument "--entity-class"') before touching the cache.
Source
Thrown at src/Tools/Console/Command/ClearCache/EntityRegionCommand.php:72
not all cache providers are able to flush entries, because of a limitation of its execution nature.
EOT);
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$ui = (new SymfonyStyle($input, $output))->getErrorStyle();
$em = $this->getEntityManager($input);
$entityClass = $input->getArgument('entity-class');
$entityId = $input->getArgument('entity-id');
$cache = $em->getCache();
if (! $cache instanceof Cache) {
throw new InvalidArgumentException('No second-level cache is configured on the given EntityManager.');
}
if (! $entityClass && ! $input->getOption('all')) {
throw new InvalidArgumentException('Invalid argument "--entity-class"');
}
if ($input->getOption('flush')) {
$cache->getEntityCacheRegion($entityClass)
->evictAll();
$ui->comment(sprintf('Flushing cache provider configured for entity named <info>"%s"</info>', $entityClass));
return 0;
}
if ($input->getOption('all')) {
$ui->comment('Clearing <info>all</info> second-level cache entity regions');
$cache->evictEntityRegions();
return 0;
}View on GitHub (pinned to d9b9ff7301)
Solutions
- Pass the entity class: orm:clear-cache:region:entity 'App\Entity\User' (an optional second argument evicts one entry by id).
- Pass --all to evict every entity region.
- Check --help for the exact argument order before scripting it.
Example fix
# before $ php bin/console doctrine:orm:clear-cache:region:entity # InvalidArgumentException: Invalid argument "--entity-class" # after $ php bin/console doctrine:orm:clear-cache:region:entity "App\Entity\User" # or all entity regions: $ php bin/console doctrine:orm:clear-cache:region:entity --all
Defensive patterns
Strategy: validation
Validate before calling
// before invoking the command
$entityClass = 'App\Entity\User';
if ($entityClass === null && ! $all) {
throw new LogicException('Provide an entity class, or pass --all.');
} Try / catch
Catch \InvalidArgumentException around the command execution and re-raise as a usage error with the exact command syntax in the message.
Prevention
- Script the exact usage line from --help (class argument, optional id, --all).
- Prefer naming the class explicitly in deploy scripts; reserve --all for full flushes.
When it happens
Trigger: Running the command with no arguments and no --all; passing only --entity-id; passing an option where the positional class argument is expected.
Common situations: Deploy snippets written for the --all behaviour but missing the flag; automation assuming a default 'clear everything' semantic; command syntax mixed up with the region:query command.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- No second-level cache is configured on the given EntityManag
- Missing arguments "--owner-class" "--association"
- No second-level cache is configured on the given EntityManag
- No second-level cache is configured on the given EntityManag
- No Metadata cache driver is configured on given EntityManage
AI-assisted analysis of doctrine/orm@d9b9ff7301 (2026-08-21).
Data as JSON: /api/errors/2f15a45da476ed6a.
Report an issue: GitHub.