serge-community / zing

Translation server for continuous localization.
https://evernote.github.io/zing/
GNU General Public License v3.0
59 stars 32 forks source link

Bugfix/localization 926 #478

Closed mandrade2 closed 2 years ago

mandrade2 commented 4 years ago

In this PR issue #253 is resolved. Whenever a submission is being saved, a stored procedure checks that with a SELECT ... FOR UPDATE row lock that the submission to be saved is not there yet. This prevents duplicate submission being saved. Making rows unique setting a multi-column index or unique_together in Django would've been preferred, but the older duplicate submissions needed to be there for consistency. Besides, Django does not support QuerySet.select_for_update() For MySQL databases.

Travis jobs where configured to run with Mysql, so the migration and testing job succeed.

All database defaults where set to have a correct character set and collation. Since by default MySQL does not store 4 byte-characters for the utf8 character set. It's explained here https://stackoverflow.com/a/20349552/8763522

mandrade2 commented 4 years ago

I fixed the remaining issues regarding tests. It turns out that I had to modify the submission save method to call for a reload from the database, to avoid Django raising an error because of garbage collecting an unsaved instance. Also added to the stored procedure arguments for a suggestion_id and quality_check_id, I had forgotten them.

I rolled back all the snapshot changes and fixed two tests that kept failing. The _test_user_purging test was failing because when asserting that two datetimes where equal, the dates from MySQL were coming back from the db without microseconds. My solution was to strip microseconds of the object that we test against. The other test was test_timeline_view_unit_with_creation. It failed because the submission unit was saved twice, which in turn called twice a method from the Unit save method called add_initial_submission. Plus, there was another call to add_initial_submission on the test itself. I removed one call to the unit save method and also the extra add_initial_submission call. I'm not sure if this changes too much the tested case on the test. You can see on both tests that it was expected for them to behave different when being tested on MySQL.