Troubleshooting¶
Common problems when working on the core and how to fix them.
Service not autowired¶
Symptom: Cannot autowire service "App\Service\MyService" or the service simply isn't
injected.
Causes and fixes:
-
Namespace mismatch — the class namespace must start with
App\: -
Excluded in config — check
config/services.yamlfor anyexclude:patterns that cover your file path. Services in excluded directories must be registered manually. -
Stale cache — clear it:
Route not found¶
Symptom: No route found for "GET /my-path" or a 404 with no error detail.
Fixes:
-
Verify the
#[Route]attribute is correct on the controller method: -
List all registered routes and search:
-
Clear the route cache:
Doctrine mapping error¶
Symptom: Mapping exception, Class ... does not exist, or entity not persisted.
Fixes:
-
Entity must be in
src/Entity/with namespaceApp\Entity\: -
Check attribute syntax — use
#[ORM\Column], not@ORM\Columnannotations. -
Validate the schema:
-
Generate and review a migration:
N+1 query in a list page¶
Symptom: Page works but is slow; Symfony Profiler shows 50+ nearly identical queries.
Diagnosis:
Open the Symfony Profiler (the debug toolbar at the bottom of the page in dev mode) →
Database tab. Look for repeated SELECT … WHERE id = ? queries.
Fix: Add leftJoin + addSelect in the repository method that powers the list:
// Before — lazy loads location for every row
public function findAll(): array
{
return $this->createQueryBuilder('e')->getQuery()->getResult();
}
// After — one query with JOIN
public function findAllWithLocation(): array
{
return $this->createQueryBuilder('e')
->leftJoin('e.location', 'l')
->addSelect('l')
->getQuery()
->getResult();
}
Fixture reference not found¶
Symptom: RuntimeException: Error retrieving reference 'Event::some-name'
Causes:
-
Wrong reference name — use the fixture class constants:
-
Load order — the fixture that calls
addRefXxx()must run before the fixture that callsgetRefXxx(). Declare dependencies: -
Wrong group — ensure both fixtures are in the same group (or the dependency's group is a subset of the dependent's group).
Template variable undefined¶
Symptom: Variable "myVar" does not exist in Twig strict mode.
Fixes:
-
Ensure the controller passes the variable to the template:
-
Debug in the template:
-
If the variable is optional, use
default:
Translation key missing¶
Symptom: The raw key string (e.g. event.title.label) appears on the page instead of
the translated text.
Fix:
- Add the key to
translations/messages.en.yaml - Run the extraction command to sync:
- Fill missing DE/CN translations:
Cache stale after config change¶
Symptom: A config change or new service registration isn't being picked up.
In dev mode, the cache auto-refreshes on most file changes, but config/container changes sometimes require a manual clear.