Merge lp://staging/~jtv/launchpad/bug-599254 into lp://staging/launchpad/db-devel

Proposed by Jeroen T. Vermeulen
Status: Merged
Approved by: Jeroen T. Vermeulen
Approved revision: no longer in the source branch.
Merged at revision: 9502
Proposed branch: lp://staging/~jtv/launchpad/bug-599254
Merge into: lp://staging/launchpad/db-devel
Diff against target: 90 lines (+21/-15)
2 files modified
lib/lp/translations/model/potmsgset.py (+8/-1)
lib/lp/translations/model/translationmessage.py (+13/-14)
To merge this branch: bzr merge lp://staging/~jtv/launchpad/bug-599254
Reviewer Review Type Date Requested Status
Māris Fogels (community) rc Approve
Henning Eggers (community) code Approve
Review via email: mp+28618@code.staging.launchpad.net

Commit message

Ensure defined flushing order when making TranslationMessages current.

Description of the change

= Bug 599254 =

When translating a given message in a given template to a given language, only one TranslationMessage can have the is_current flag set and only one can have the is_imported flag set. The database ensures this through unique constraints.

In the current code (which we are working to replace entirely) we have validator functions that keep us within the bounds of those constraints. Whenever we set a TM's is_current to True, the corresponding validator first finds the message that previously had the flag set, if any, and clears the flag there. Same for the is_imported flag. They also tell the ORM that the change clearing the old flag needs to be flushed to the database before the change setting the new one.

These validators only look for translations that are for the same template. This is not as simple as it seems: with message sharing, most messages will have their template set to None which means they're shared across templates. Things quickly get confusing when changes to these flags are combined with changes to the TranslationMessage.potemplate field. Bug 599254 involves violations of the unique constraints (i.e, oopses) as the ORM flushes changes in an inconvenient order.

In this branch I'm making a minimal change to define flush order in cases where we were already clearing flags but not running the affected TranslationMessages through the validators. There are no functional changes. It looks probable that re-ordering the changes to TranslationMessages could also have solved the problem, but that would involve a risk of unintended functional changes. Our "recife" project is going to replace the entire cluster of methods that triggers the problem, as well as the validators. Not a good time for finicky unpredictable tweaks.

In the validators I did have to add an extra check against defining flush order between a TranslationMessage and itself. Some of the tests triggered such an error at one point.

I found myself unable to come up with a sensible test for this that doesn't take a lot of work or duplicate lots of other tests. We already have tons of tests covering the methods involved, and those all pass with my change.

To test, run all translations tests but in particular:
{{{
./bin/test -vv -t potmsgset -t translationmessage
}}}

There was one piece of lint in code I haven't touched: an unnecessary assignment. I'm leaving it intact to avoid conflicts with the ongoing Recife work that will touch the same code.

Jeroen

To post a comment you must log in.
Revision history for this message
Henning Eggers (henninge) wrote :

Thanks for the quick fix.

57 + Store.of(self).add_flush_order(
58 + current_translation_message, self)

These two fit on one line, I think.

Cheers,
Henning

review: Approve (code)
Revision history for this message
Jeroen T. Vermeulen (jtv) wrote :

Indeed it does. Thanks for the review!

Revision history for this message
Henning Eggers (henninge) wrote :

Hi Maris,
could you please review this for an r-c? It fixes an oops that would hinder translators in their daily work.

Cheers,
Henning

Revision history for this message
Māris Fogels (mars) wrote :

Great work, nice explanation of the problem and solution. release-critical=mars

review: Approve
Revision history for this message
Māris Fogels (mars) :
review: Approve (rc)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
The diff is not available at this time. You can reload the page or download it.

Subscribers

People subscribed via source and target branches

to status/vote changes: