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
[4.0] Fix SQL error 1093 "You can't specify target table ..." when updating from 3.10 with certain versions of MySQL 5.7 #34763
Conversation
I think it's a release blocker if updates break on particular MySQL versions which are supported by J4. |
Tested the SQL on a mariaDB in a J3 application and works fine.
|
Thanks. Not a full test for the issue, but at least we know nothing is broken for MariaDB. |
So far: |
That sounds good so far. |
Tomorrow night RC 4 will be released, so there is not much time if we want to get this fix into RC 4. |
@obuisard Have you meanwhile found time to complete your test? If so, please mark your test result in the issue tracker here https://issues.joomla.org/tracker/joomla-cms/34763 by using the "Test this" button, selecting the appropriate test result and submitting. There would be a change to get it into RC 4 today but we need at least your test completed. Thanks in advance. |
I don't have MySQL 5.7.14 to test. However, I tested update with MySQL 5.7.29 and everything is working as expected. |
I have tested this item ✅ successfully on 7b9fa98 This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/34763. |
I think as the others have tested the other databases, we can say that's one successful test for all in total. |
@obuisard Thanks for testing. |
You are welcome @richard67. This was a difficult one, thank you for looking into it! |
Thanks! |
Because there is another issue which results in the same SQL error 1093 but could only be reproduced with MySQL 5.7.9 and not with the 5.7.14 used here, I have checked if this fix here also works for MySQL 5.7.9. Thanks god it does, at least with the database server being 5.7.9 (the webserver and so the db client were newer). |
Pull Request for Issue #32888 .
Summary of Changes
This pull request (PR) adds proper names quoting and correct use of table aliases to the SQL statement for inserting the new template styles when updating from 3.10 to 4.
This fixes issue #32888 , which happens only on particular versions of MySQL 5.7 and results in the update from 3.10 to 4 being broken because the SQL updates fail with SQL error 1093 when executing the statement modified by this PR.
For sure MySQL version 5.7.14 which has been reported in issue #32888 has that problem, and very likely also version 5.7.9 which has been reported in issue #22231 , which has the same cause.
With MySQL 5.6 I could not reproduce the problem, and later versions of MySQL than the one mentioned above seem not to have the problem either.
The same changes as for MySQL are done for the PostgreSQL update script for consistency and for being safe from PostgreSQL becoming more strict in future regarding correct quoting of names which are equal to reserved words (e.g. "count").
Testing Instructions
Test 1: Reproduce the issue
For reproducing the issue it needs a MySQL database server version 5.7.14.
Because I haven't found any XAMPP version which includes this MySQL version, it needs to set up a MySQL server of that version.
You can find the downloads here: https://downloads.mysql.com/archives/installer/ .
Make sure that you have selected version 5.7.14 before downloading.
If that link doesn't work for you (not sure if it requires an Oracle Tech Network account), you can also download it from here: https://test5.richard-fath.de/mysql-installer-community-5.7.14.0.msi (MD5 checksum is b4df226b58390f8b3d02d264a785e715).
Make an installation of MySQL server including the client tools, if necessary on a separate (virtual) computer if you don't want to mess up your existing installation e.g. of XAMPP, and then use that database server from remote, i.e. not use "localhost" but the FQDN of that database server for your Joomla installation.
Make a new installation of current 3.10-dev or latest nightly or the last alpha version, using a PHP version which is supported by Joomla 4 and the database server prepared as described above.
Try to update that 3.10 installation to the latest 4.0 nightly build.
Result: See issue #32888. The update fails with SQL error "1093 You can't specify target table '#__template_styles' for update in FROM clause", and frontend and backend are broken.
When checking for the last SQL statement logged in the update log "administrator/logs/joomla_update.php", it is the statement coming just before the one modified by this PR.
Test 2: Verify that this PR fixes the issue
Result: The update succeeds. There is only the usual alert about the missing template found, which disappears after navigating around in backend.
Result: There is one problem shown for the CMS.
Result: Only the usual version problem.
Result: Atum is the default backend template, and Cassiopeia is the default frontend template.
Test 3: Verify that the SQL statement modified by this PR still does what it shall do
Start again with a 3.10 and an empty database and attempt to update to the patched J4 package for this PR , but before updating create a copy of the Protostar template and make this copy the default frontend template.
Verify if the new J4 templates are default templates.
Result: Atum is the default backend template, but Cassiopeia is not the default frontend template. This is still the copy of Protostar, and so frontend will be broken.
Alternatively you could install a 3rd party template on 3.10 before updating, which is compatible to 3.10 and 4, if you can find such a template, and make that the default.
Testing the same for the backend template will be harder. You need to find one which is compatible to 3.10 and 4 and make that the default backend template before updating.
The result in general should be:
If the Protostar or the beez3 template is the default frontend template on 3.10, Cassiopeia will be the default frontend template after the update, otherwise not, and if the Isis or the Hathor template is the default backend template on 3.10, Atum will be the default backend template after the update, otherwise not.
Test 4: Verify that nothing is broken for other MySQL versions or PostgreSQL
Execute test 3 on any other version of MySQL than those which have the issue, or on any PostgreSQL version.
The result should be the same.
Actual result BEFORE applying this Pull Request
When using certain versions of MySQL 5.7, e.g. for sure 5.7.14, as database server, an update from any 3.10 version to current J4 is broken because the SQL updates fail with SQL error 1093 when executing the statement modified by this PR at the very beginning of the database updates.
When using the button to go to the control panel, the backend is broken and looks like this:
Expected result AFTER applying this Pull Request
Updates from 3.10 to 4 succeed with these MySQL versions, and for other versions of MySQL or for MariaDB or PostgreSQL nothing changes.
Documentation Changes Required
None.