-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Translator] Resource loading order depends on kernel.debug setting #23034
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
ping @aitboudad – you've been involved in much of this code, maybe you can help |
Basically the problem is that injecting the Translator will trigger the loading of resources (which may not be needed for this service). Eg. the translator resources loading must be made lazy (at least for the framework) or we need a wrapper service that will lazy initialize the translator? |
I was suspecting something like that. In #23057, resource loading should still be lazy but with a consistent order in debug/prod environments. |
…inconsistency reported in #23034 (mpdude) This PR was squashed before being merged into the 2.7 branch (closes #23057). Discussion ---------- [Translation][FrameworkBundle] Fix resource loading order inconsistency reported in #23034 | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #23034 | License | MIT | Doc PR | Fixes the bug reported in #23034: When mixing `addResource()` calls and providing the `resource_files` option, the order in which resources are loaded depends on the `kernel.debug` setting and whether a cache is used. In particular, when several loaders provide translations for the same message, the one that "wins" may change between development and production mode. Commits ------- 2a9e65d [Translation][FrameworkBundle] Fix resource loading order inconsistency reported in #23034
* 2.7: [Routing] Fix XmlFileLoader exception message Sessions: configurable "use_strict_mode" option for NativeSessionStorage [FrameworkBundle] [Command] Clean bundle directory, fixes #23177 Reset redirectCount when throwing exception [TwigBundle] Remove template.xml services when templating is disabled add content-type header on exception response Embedding a response that combines expiration and validation, that should not defeat expiration on the combined response Fix two edge cases in ResponseCacheStrategy [Routing] Expose request in route conditions, if needed and possible [Routing] Expose request in route conditions, if needed and possible [Translation][FrameworkBundle] Fix resource loading order inconsistency reported in #23034 [Filesystem] added workaround in Filesystem::rename for PHP bug Add tests for ResponseCacheStrategy to document some more edge cases [HttpFoundation] added missing docs fixes #21606 [VarDumper] fixes [Security] fix switch user _exit without having current token
* 2.8: (40 commits) Show exception is checked twice in ExceptionController of twig allow SSI fragments configuration in XML files Display a better error message when the toolbar cannot be displayed render hidden _method field in form_rest() return fallback locales whenever possible [Console] Fix catching exception type in QuestionHelper [WebProfilerBundle] Eliminate line wrap on count columnt (routing) [Routing] Fix XmlFileLoader exception message [Translation] Fix FileLoader::loadResource() php doc Sessions: configurable "use_strict_mode" option for NativeSessionStorage [FrameworkBundle] [Command] Clean bundle directory, fixes #23177 Reset redirectCount when throwing exception [TwigBundle] Remove template.xml services when templating is disabled add content-type header on exception response Embedding a response that combines expiration and validation, that should not defeat expiration on the combined response Fix two edge cases in ResponseCacheStrategy [Routing] Expose request in route conditions, if needed and possible [Routing] Expose request in route conditions, if needed and possible [Translation][FrameworkBundle] Fix resource loading order inconsistency reported in #23034 [Filesystem] added workaround in Filesystem::rename for PHP bug ...
* 2.8: (40 commits) Show exception is checked twice in ExceptionController of twig allow SSI fragments configuration in XML files Display a better error message when the toolbar cannot be displayed render hidden _method field in form_rest() return fallback locales whenever possible [Console] Fix catching exception type in QuestionHelper [WebProfilerBundle] Eliminate line wrap on count columnt (routing) [Routing] Fix XmlFileLoader exception message [Translation] Fix FileLoader::loadResource() php doc Sessions: configurable "use_strict_mode" option for NativeSessionStorage [FrameworkBundle] [Command] Clean bundle directory, fixes symfony#23177 Reset redirectCount when throwing exception [TwigBundle] Remove template.xml services when templating is disabled add content-type header on exception response Embedding a response that combines expiration and validation, that should not defeat expiration on the combined response Fix two edge cases in ResponseCacheStrategy [Routing] Expose request in route conditions, if needed and possible [Routing] Expose request in route conditions, if needed and possible [Translation][FrameworkBundle] Fix resource loading order inconsistency reported in symfony#23034 [Filesystem] added workaround in Filesystem::rename for PHP bug ...
Uh oh!
There was an error while loading. Please reload this page.
In 027a747, #13897 was merged. This was a performance improvement: Instead of calling the (expensive?)
Translator::addResource
method when creating theTranslator
instance in the DIC, only an array of resources would be passed toTranslator::__construct
.Translator::loadResources
would then iterate over this array and make the actualaddResource
call, but not unlessTranslator::initializeCatalogue
is called.Then, e36f1a7 tries to fix a bug with not reloading the messages. It does so by adding another
Translator::loadResources
call inTranslator::loadCatalogue()
, but only does this inkernel.debug
mode (assuming messages don't change inprod
).Then, in aa70a94, this
loadCatalogue
overriden method was removed again and theloadResources
-if-in-debug code slipped into the constructor.I admin that I cannot really follow the ideas behind all these changes. However, the bottom line is that in
kernel.debug
mode, the resources passed to the constructor are turned intoaddResource()
calls immediately, whereas in production mode this is deferred untilinitialize()
/initializeCatalogue()
are called.This is a problem for other bundles/extensions that add additional resources to the
Translator
viaaddResource()
calls (for example added to the DIC): Depending on thekernel.debug
setting, these resources will be loaded first or last, which makes the resource override (or "lose" against) other message sources.Assuming that message source priority should not change between debug and prod, I see the following options:
a) Always add resources passed in the
resource_files
option in the constructor. Probably defeats the initial performance improvement intention?b) Always defer adding
resource_files
untilinitialize()
is called. That way, resources added viaaddResource()
by 3rd party bundles always have a lower priority thanresource_files
.c) Change the private
loadResources()
method in a way that "shifts" the resources before those added byaddResource()
calls (where they would end up if they were added in the constructor).Additionally, if in production it is no problem to defer this initialization until
initialize()
is called, why is it necessary to perform this step in the constructor underkernel.debug
?Update: Suggested fix in #23057
The text was updated successfully, but these errors were encountered: