Skip to content

Error on Symfony container build: You must configure a hydrator directory. See docs for details. #1911

@melkamar

Description

@melkamar

Bug Report

Q A
Version 2.15.1
Symfony version ✅ 7.1.1
Symfony version ❌ 7.1.2

Summary

After upgrading Symfony from 7.1.0 to latest, plain cache:clear started giving an error:

In HydratorException.php line 23:

  You must configure a hydrator directory. See docs for details.

When I checked the generated Container file, the whole configuration section of the getDoctrineMongodb_Odm_DefaultDocumentManagerService was missing (screenshot below shows the correct, working state; in the broken, there is no config). That's why this error is thrown - there really was no configuration made in the container:

Image

I have traced the issue back to this exact commit and line in Symfony: symfony/symfony@d4b812c#diff-2a36924e0448b459f1261198e19953b5a8f143a591a7298c18f0bb47ba04b6bbL134. Adding back the line of

ksort($services);

Into the ServiceLocatorTagPass fixed the issue. Then I dug deeper and found out, that the ksort addition is really only needed when a particular set of services is being processed there. In my case, it was these services, in this order:

doctrine.orm.messenger.doctrine_schema_listener
doctrine.orm.listeners.doctrine_dbal_cache_adapter_schema_listener
doctrine.orm.listeners.doctrine_token_provider_schema_listener
doctrine.orm.listeners.pdo_session_handler_schema_listener
doctrine.orm.listeners.lock_store_schema_listener
doctrine.orm.default_listeners.attach_entity_listeners

Through more testing, I found out that the relative order of these two services is important:

doctrine.orm.messenger.doctrine_schema_listener
doctrine.orm.listeners.pdo_session_handler_schema_listener

This order does not work, but if the doctrine_schema_listener comes after the other, then things start working. Coincidentally, due to the alphabetical ordering of the (now-removed) ksort() method, this is exactly what was happening - the order of these two got flipped by sheer luck.

To verify this, I went to the service definition file messenger.xml and adjusted the priorities as:

<service id="doctrine.orm.messenger.doctrine_schema_listener" class="Symfony\Bridge\Doctrine\SchemaListener\MessengerTransportDoctrineSchemaListener">
    <argument type="tagged_iterator" tag="messenger.receiver" />
    <tag name="doctrine.event_listener" event="postGenerateSchema" priority="-1" />
    <tag name="doctrine.event_listener" event="onSchemaCreateTable" priority="-1" />
</service>

After this change, the error went away and the container built correctly. Unfortunately, I don't know enough about Doctrine to be able to tell why, or whether that is the correct fix to make. As a temporary solution to allow us to proceed with the upgrade, I implemented a custom Symfony compiler pass that assigns these new priorities from our code.

I assume this may be affected by something else in our environment, as this probably works well for many other people, since I could not find nearly anything with this error on the internet. I have no idea how to build a reproducer for this. This is in a massive monolith project 10+ years old.

Current behavior

With Symfony 7.1.2+ container build fails.

Expected behavior

It should not fail.

Library versions

``` alcaeus/mongo-php-adapter 1.2.5 allejo/php-vcr-sanitizer dev-rh/1.1.0-base 39d07c8 amphp/amp 3.1.0 amphp/byte-stream 2.1.2 amphp/cache 2.0.1 amphp/dns 2.4.0 amphp/parallel 2.3.1 amphp/parallel-functions 2.0.0 amphp/parser 1.1.1 amphp/pipeline 1.2.3 amphp/process 2.0.3 amphp/serialization 1.0.0 amphp/socket 2.3.1 amphp/sync 2.3.0 aws/aws-crt-php 1.2.7 aws/aws-sdk-php 3.337.3 beberlei/assert 3.3.3 brick/math 0.13.1 clue/ndjson-react 1.3.0 clue/stream-filter 1.7.0 composer/ca-bundle 1.5.7 composer/class-map-generator 1.6.1 composer/composer 2.7.7 composer/metadata-minifier 1.0.0 composer/pcre 3.1.4 composer/semver 3.4.3 composer/spdx-licenses 1.5.9 composer/xdebug-handler 3.0.5 daverandom/libdns 2.1.0 dms/phpunit-arraysubset-asserts 0.2.1 doctrine/annotations 1.14.4 doctrine/cache 2.1.1 doctrine/collections 2.3.0 doctrine/common 3.5.0 doctrine/data-fixtures 1.8.2 doctrine/dbal 3.10.1 doctrine/deprecations 1.1.5 doctrine/doctrine-bundle 2.15.1 doctrine/doctrine-fixtures-bundle 3.6.2 doctrine/event-manager 2.0.1 doctrine/inflector 2.1.0 doctrine/instantiator 2.0.0 doctrine/lexer 2.1.1 doctrine/mongodb-odm 2.10.2 doctrine/mongodb-odm-bundle 5.3.1 doctrine/orm 2.20.6 doctrine/persistence 3.3.3 doctrine/sql-formatter 1.5.2 dragonmantank/cron-expression 3.4.0 egulias/email-validator 4.0.4 elastic/transport 8.11.0 elasticsearch/elasticsearch 8.19.0 emag-tech-labs/messenger-mongo-bundle 1.3.0 erasys/openapi-php dev-rh/4.0.0-base 348b4af erusev/parsedown 1.7.4 evenement/evenement 3.0.2 ezyang/htmlpurifier 4.18.0 fakerphp/faker 1.23.1 fidry/cpu-core-counter 1.3.0 firebase/php-jwt 5.5.1 friendsofphp/php-cs-fixer 3.59.3 friendsofphp/proxy-manager-lts 1.0.18 geocoder-php/common-http 4.7.0 geocoder-php/google-maps-provider 4.8.0 geocoder-php/plugin 1.6.0 gesdinet/jwt-refresh-token-bundle 1.5.0 giggsey/libphonenumber-for-php 8.13.55 giggsey/locale 2.8.0 gitonomy/gitlib 1.5.0 google/apiclient 2.14.0 google/apiclient-services 0.407.0 google/auth 1.26.0 guzzlehttp/guzzle 7.9.3 guzzlehttp/promises 2.2.0 guzzlehttp/psr7 2.7.1 hautelook/alice-bundle 2.13.0 illuminate/contracts 10.48.28 imagine/imagine 1.5.0 incenteev/composer-parameter-handler 2.2.0 jane-php/json-schema 7.9.0 jane-php/json-schema-runtime 7.9.0 jane-php/open-api-3 7.9.0 jane-php/open-api-common 7.9.0 jane-php/open-api-runtime 7.9.0 jean85/pretty-package-versions 2.1.1 jmikola/geojson 1.2.0 jms/metadata 2.8.0 jms/serializer 3.32.5 jms/serializer-bundle 5.5.1 johnkary/phpunit-speedtrap 3.3.0 justinrainbow/json-schema 5.3.0 jwadhams/json-logic-php 1.5.1 kelunik/certificate 1.1.3 knplabs/knp-snappy 1.5.1 knplabs/knp-snappy-bundle 1.10.4 laminas/laminas-code 4.16.0 laravel/serializable-closure 1.3.7 lcobucci/clock 3.3.1 lcobucci/jwt 5.5.0 league/flysystem 3.30.0 league/flysystem-aws-s3-v3 3.29.0 league/flysystem-azure-blob-storage 3.30.0 league/flysystem-bundle 3.5.0 league/flysystem-local 3.30.0 league/flysystem-memory 3.29.0 league/mime-type-detection 1.16.0 league/oauth2-client 2.8.1 league/uri 7.5.1 league/uri-interfaces 7.5.0 lexik/jwt-authentication-bundle 2.21.0 liip/imagine-bundle 2.13.3 liuggio/fastest 1.12.0 lmc/http-constants 1.2.0 maennchen/zipstream-php 3.2.0 majermi4/friendly-config dev-main 53a8a30 markbaker/complex 3.0.2 markbaker/matrix 3.0.1 masbug/flysystem-google-drive-ext 2.4.1 masterminds/html5 2.10.0 microsoft/azure-storage-blob 1.5.4 microsoft/azure-storage-common 1.5.2 microsoft/microsoft-graph 1.110.0 mongodb/mongodb 1.20.0 monolog/monolog 3.9.0 mtdowling/jmespath.php 2.8.0 myclabs/deep-copy 1.13.4 namshi/jose 7.2.3 nelmio/alice 3.14.2 nelmio/cors-bundle 2.5.0 nelmio/security-bundle 3.1.1 nette/php-generator 4.1.9 nette/utils 4.0.8 nikic/iter 2.4.1 nikic/php-parser 5.6.1 nyholm/psr7 1.8.2 ondram/ci-detector 4.2.0 onelogin/php-saml 3.8.0 open-telemetry/api 1.4.0 open-telemetry/context 1.3.1 paragonie/constant_time_encoding 3.0.0 paragonie/halite 5.1.3 paragonie/hidden-string 2.2.0 paragonie/random_compat 9.99.100 paragonie/sodium_compat 2.1.0 pelago/emogrifier 7.3.0 phar-io/manifest 2.0.4 phar-io/version 3.2.1 php-http/client-common 2.7.2 php-http/curl-client 2.3.3 php-http/discovery 1.20.0 php-http/guzzle7-adapter 1.1.0 php-http/httplug 2.4.1 php-http/message 1.16.2 php-http/multipart-stream-builder 1.4.2 php-http/promise 1.3.1 php-http/vcr-plugin 1.2.3 php-jsonpointer/php-jsonpointer 4.0.0 php-vcr/php-vcr dev-master 045d02c phpcollection/phpcollection 0.6.0 phpdocumentor/reflection-common 2.2.0 phpdocumentor/reflection-docblock 5.6.2 phpdocumentor/type-resolver 1.10.0 phpoffice/phpspreadsheet 1.30.0 phpoption/phpoption 1.9.3 phpro/grumphp 2.10.0 phpseclib/phpseclib 3.0.46 phpstan/phpdoc-parser 1.33.0 phpstan/phpstan 1.10.67 phpstan/phpstan-doctrine 1.3.69 phpstan/phpstan-symfony 1.3.12 phpstan/phpstan-webmozart-assert 1.2.10 phpunit/php-code-coverage 9.2.32 phpunit/php-file-iterator 3.0.6 phpunit/php-invoker 3.1.1 phpunit/php-text-template 2.0.4 phpunit/php-timer 5.0.3 phpunit/phpunit 9.6.24 psr/cache 3.0.0 psr/clock 1.0.0 psr/container 2.0.2 psr/event-dispatcher 1.0.0 psr/http-client 1.0.3 psr/http-factory 1.1.0 psr/http-message 1.1 psr/link 2.0.1 psr/log 3.0.2 psr/simple-cache 3.0.0 ralouphie/getallheaders 3.0.3 ramsey/collection 2.1.1 ramsey/uuid 4.9.0 react/cache 1.2.0 react/child-process 0.6.6 react/dns 1.13.0 react/event-loop 1.5.0 react/promise 3.2.0 react/socket 1.16.0 react/stream 1.4.0 revolt/event-loop 1.0.7 robrichards/xmlseclibs 3.1.3 rohea/file-storage 0.1.1 sabberworm/php-css-parser 8.9.0 sebastian/cli-parser 1.0.2 sebastian/code-unit 1.0.8 sebastian/code-unit-reverse-lookup 2.0.3 sebastian/comparator 4.0.9 sebastian/complexity 2.0.3 sebastian/diff 4.0.6 sebastian/environment 5.1.5 sebastian/exporter 4.0.6 sebastian/global-state 5.0.8 sebastian/lines-of-code 1.0.4 sebastian/object-enumerator 4.0.4 sebastian/object-reflector 2.0.4 sebastian/recursion-context 4.0.6 sebastian/resource-operations 3.0.4 sebastian/type 3.2.1 sebastian/version 3.0.2 seld/jsonlint 1.11.0 seld/phar-utils 1.2.1 seld/signal-handler 2.0.2 sentry/sentry 4.14.2 sentry/sentry-symfony 5.3.1 spatie/phpunit-snapshot-assertions 4.2.17 stevenmaguire/oauth2-salesforce 2.0.1 symfony/asset 7.3.0 symfony/browser-kit 7.3.2 symfony/cache 7.3.2 symfony/cache-contracts 3.6.0 symfony/clock 7.3.0 symfony/config 7.3.2 symfony/console 7.3.2 symfony/css-selector 7.3.0 symfony/debug-bundle 7.3.0 symfony/dependency-injection 7.3.2 symfony/deprecation-contracts 3.6.0 symfony/doctrine-bridge 7.3.2 symfony/doctrine-messenger 7.3.2 symfony/dom-crawler 7.3.1 symfony/dotenv 7.3.2 symfony/error-handler 7.3.2 symfony/event-dispatcher 7.3.0 symfony/event-dispatcher-contracts 3.6.0 symfony/expression-language 7.3.2 symfony/filesystem 7.3.2 symfony/finder 7.3.2 symfony/form 7.3.2 symfony/framework-bundle 7.3.2 symfony/http-client 7.3.2 symfony/http-client-contracts 3.6.0 symfony/http-foundation 7.3.2 symfony/http-kernel 7.3.2 symfony/intl 7.3.2 symfony/lock 7.3.2 symfony/mailer 7.3.2 symfony/maker-bundle 1.64.0 symfony/mercure 0.6.5 symfony/mercure-bundle 0.3.9 symfony/messenger 7.3.2 symfony/mime 7.3.2 symfony/monolog-bridge 7.3.0 symfony/monolog-bundle 3.10.0 symfony/notifier 7.3.0 symfony/options-resolver 7.3.2 symfony/password-hasher 7.3.0 symfony/phpunit-bridge 6.4.24 symfony/polyfill-ctype 1.32.0 symfony/polyfill-intl-grapheme 1.32.0 symfony/polyfill-intl-icu 1.32.0 symfony/polyfill-intl-idn 1.32.0 symfony/polyfill-intl-normalizer 1.32.0 symfony/polyfill-mbstring 1.32.0 symfony/polyfill-php56 1.20.0 symfony/polyfill-php72 1.31.0 symfony/polyfill-php73 1.32.0 symfony/polyfill-php80 1.32.0 symfony/polyfill-php81 1.32.0 symfony/polyfill-php82 1.32.0 symfony/polyfill-php83 1.32.0 symfony/polyfill-php84 1.32.0 symfony/polyfill-uuid 1.32.0 symfony/process 7.3.0 symfony/property-access 7.3.2 symfony/property-info 7.3.1 symfony/proxy-manager-bridge 6.4.24 symfony/psr-http-message-bridge 7.3.0 symfony/routing 7.3.2 symfony/security-bundle 7.3.2 symfony/security-core 7.3.2 symfony/security-csrf 7.3.0 symfony/security-http 7.3.2 symfony/serializer 7.3.2 symfony/service-contracts 3.6.0 symfony/slack-notifier 7.3.0 symfony/stopwatch 7.3.0 symfony/string 7.3.2 symfony/translation 7.3.2 symfony/translation-contracts 3.6.0 symfony/twig-bridge 7.3.2 symfony/twig-bundle 7.3.2 symfony/type-info 7.3.2 symfony/uid 7.3.1 symfony/validator 7.3.2 symfony/var-dumper 7.3.2 symfony/var-exporter 7.3.2 symfony/web-link 7.3.0 symfony/web-profiler-bundle 7.3.2 symfony/yaml 7.3.2 thenetworg/oauth2-azure 2.0.1 theofidry/alice-data-fixtures 1.8.0 theseer/tokenizer 1.2.3 twig/intl-extra 3.21.0 twig/twig 3.21.1 ua-parser/uap-php 3.10.0 webmozart/assert 1.11.0 willdurand/geocoder 5.0.0 willdurand/geocoder-bundle 5.23.0 xylemical/php-expressions 1.2.0 zenstruck/assert 1.5.1 zenstruck/callback 1.5.0 zenstruck/foundry 1.38.6 zenstruck/schedule-bundle 1.8.1 ```

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions