Skip to content

[Translation] Revert inlining fallback catalogues as it might cause inconsistent results when a cache is used #14315

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

Merged
merged 1 commit into from
Apr 14, 2015
Merged

[Translation] Revert inlining fallback catalogues as it might cause inconsistent results when a cache is used #14315

merged 1 commit into from
Apr 14, 2015

Conversation

mpdude
Copy link
Contributor

@mpdude mpdude commented Apr 11, 2015

Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #14315
License MIT
Doc PR n/a

The results from getCatalogue() are inconsistent when we're in production and a cache comes into play.

This is due to the changes in 6eb5e73, where the fallback catalogues will be merged into the primary catalogue when it is written to the cache.

Strictly speaking, this is a BC break because it behaved differently before.

I am not sure what the relevance of this might be in practice.

However, it may cause headaches because

  • The result changes only in the second+ try (when the cache is warm); a priori you cannot tell whether you're going to see this
  • The catalogue is clearly not what the loader provided
  • You have no chance of telling whether the message was originally available in the catalogue or not
  • Generally, for every message you retrieve from the catalogue, you have no way of telling which locale it actually comes from (it need not be from the catalogue's locale, and the catalogue does not provide fallback catalogues either)

Regarding the last point, you usually don't care when using the Translator. Its purpose is to get the "best" translation available. However, when you bother to explicitly retrieve the catalogue, chances are your intentions are different.

@mpdude mpdude changed the title [Translator] getCatalogue() inconsistency when cache comes into play [Translation] getCatalogue() inconsistency when cache comes into play Apr 11, 2015
@aitboudad
Copy link
Contributor

BC break fixed in #14318.
I would agree if #14265 and #13986 has been merged into 2.7 as I think we shouldn't overlooked the impact of performance here.

@mpdude
Copy link
Contributor Author

mpdude commented Apr 11, 2015

I don't think #14318 is a solution. Just extend the test to also check the fallback catalogue and you'll see that the problem has only been shifted there.

@aitboudad
Copy link
Contributor

I used the test, isn't it?

@mpdude
Copy link
Contributor Author

mpdude commented Apr 11, 2015

Whenever you remove messages from the catalogue (currently upon caching), they will later on be missing. So I think this cannot be fixed 😦

I'd suggest we focus on caching and loading smaller chunks instead, for example only a single domain and locale at a time.

And also the #13986 attempt (however implemented) would gain so much that merging fallbacks might no longer be necessary.

@aitboudad
Copy link
Contributor

@mpdude Is there a use case for the last commit ?

@mpdude
Copy link
Contributor Author

mpdude commented Apr 12, 2015

I cannot tell. It's just that it behaved differently before and only occurs when reading from the cache in production.

I don't know what to do here - @symfony/deciders time?

@aitboudad
Copy link
Contributor

ok let's wait for the feedback :)

@aitboudad
Copy link
Contributor

FYI I agree that it should be removed in the next version 2.8

@fabpot
Copy link
Member

fabpot commented Apr 12, 2015

Haven't read the whole thing, so not sure if this is relevant, but if something introduced in 2.7 should be removed, it's still possible during the beta period.

@aitboudad
Copy link
Contributor

we should removed once #14265 and #13986 merged.

@stof
Copy link
Member

stof commented Apr 12, 2015

Note that knowing from which locale comes the translation is important when using the translator: it impacts the pluralization rules. So it this info is lost, it introduces a bug in the translator

@aitboudad
Copy link
Contributor

@stof fixed in #14318
@mpdude we should not avoid your arguments, I keep the decision for you

@mpdude
Copy link
Contributor Author

mpdude commented Apr 13, 2015

I have tried various approaches to fix MessageCatalogue::addFallbackCatalogue while keeping the optimization in place.

Although in the best case I was able to get consistent results independent of whether a cache was used or not, there would still be a difference in the messages available in the returned catalogue (all messages from a particular locale present in <= 2.6, only the actual fallbacks in 2.7).

Also, in my attempts the MessageCatalogue chain would be very fragile with results (correctness & optimization) depending on adding fallbacks in a particular order (top-down) or not changing catalogues after the optimization has been applied – at least ugly API-wise.

So, for the time being, I would like to recommend merging this PR; that is, revert the optimization introduced in 2.7.

For now, that would keep results unchanged for our users and gives us time to thoroughly think this through, before adding another (new) mode of behaviour we'd be required to support in the future.

@aitboudad
Copy link
Contributor

@mpdude ok thank you for your effort here :) , can you update the PR contribution header in the description and squash your commits.

…eb5e73

Also add a test that shows where this would cause inconsistent behaviour of the getFallbackCatalogue() method.
@mpdude mpdude changed the title [Translation] getCatalogue() inconsistency when cache comes into play [Translation] Revert inlining fallback catalogues as it might cause inconsistent results when a cache is used Apr 13, 2015
@mpdude
Copy link
Contributor Author

mpdude commented Apr 13, 2015

Done.

@aitboudad
Copy link
Contributor

👍

1 similar comment
@stof
Copy link
Member

stof commented Apr 13, 2015

👍

@aitboudad
Copy link
Contributor

Thank you @mpdude.

@aitboudad aitboudad merged commit 12a183a into symfony:2.7 Apr 14, 2015
aitboudad added a commit that referenced this pull request Apr 14, 2015
…ght cause inconsistent results when a cache is used (mpdude)

This PR was merged into the 2.7 branch.

Discussion
----------

[Translation] Revert inlining fallback catalogues as it might cause inconsistent results when a cache is used

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #14315
| License       | MIT
| Doc PR        | n/a

The results from `getCatalogue()` are inconsistent when we're in production *and* a cache comes into play.

This is due to the changes in 6eb5e73, where the fallback catalogues will be *merged* into the primary catalogue when it is written to the cache.

Strictly speaking, this is a BC break because it behaved differently before.

I am not sure what the relevance of this might be in practice.

However, it may cause headaches because
* The result changes only in the second+ try (when the cache is warm); a priori you cannot tell whether you're going to see this
* The catalogue is clearly not what the loader provided
* You have no chance of telling whether the message was originally available in the catalogue or not
* Generally, for every message you retrieve from the catalogue, you have no way of telling which locale it actually comes from (it need not be from the catalogue's locale, and the catalogue does not provide fallback catalogues either)

Regarding the last point, you usually don't care when using the `Translator`. Its purpose is to get the "best" translation available. However, when you bother to explicitly retrieve the catalogue, chances are your intentions are different.

Commits
-------

12a183a Revert inlining the fallback messages in production that was added in 6eb5e73
@mpdude mpdude deleted the translator-get-catalogue-inconsistent branch April 16, 2015 19:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants