Skip to content

tests: Invalid DATETIME test fails with mysql >= 8.0.24 #1208

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

Closed
paride opened this issue Sep 2, 2021 · 3 comments · Fixed by #1221
Closed

tests: Invalid DATETIME test fails with mysql >= 8.0.24 #1208

paride opened this issue Sep 2, 2021 · 3 comments · Fixed by #1221

Comments

@paride
Copy link

paride commented Sep 2, 2021

The test suite is failing when running against MySQL >= 8.0.24 with:

Failures:

  1) Mysql2::Result row data type mapping should raise an error given an invalid DATETIME
     Failure/Error:
       expect { @client.query("SELECT CAST('1972-00-27 00:00:00' AS DATETIME) as bad_datetime").each }.to \
         raise_error(Mysql2::Error, "Invalid date in field 'bad_datetime': 1972-00-27 00:00:00")

       expected Mysql2::Error with "Invalid date in field 'bad_datetime': 1972-00-27 00:00:00" but nothing was raised
     # ./spec/mysql2/result_spec.rb:321:in `block (3 levels) in <top (required)>'

  2) Mysql2::Statement row data type mapping should raise an error given an invalid DATETIME
     Failure/Error:
       expect { @client.query("SELECT CAST('1972-00-27 00:00:00' AS DATETIME) as bad_datetime").each }.to \
         raise_error(Mysql2::Error, "Invalid date in field 'bad_datetime': 1972-00-27 00:00:00")

       expected Mysql2::Error with "Invalid date in field 'bad_datetime': 1972-00-27 00:00:00" but nothing was raised
     # ./spec/mysql2/statement_spec.rb:478:in `block (3 levels) in <top (required)>'

This is because according to the release notes (https://dev.mysql.com/doc/relnotes/mysql/8.0/en/news-8-0-24.html):

Using CAST() on a DATE or DATETIME value in an INSERT statement raised a warning for "0000-00-00" and "2000-02-31", but not for "2000-01-00" or "2000-00-01". Now a warning is shown in each of these cases also.

The statement_spec.rb and result_spec.rb files need to be updated with a bad date that still generates an error, e.g. 2000-01-00.

@casperisfine
Copy link
Contributor

This is tricky, because it seems that casting to datetime pretty much never error out anymore, but just shows a warning:

mysql> SELECT CAST('WAT' AS DATETIME); SHOW WARNINGS;
+-------------------------+
| CAST('WAT' AS DATETIME) |
+-------------------------+
| NULL                    |
+-------------------------+
1 row in set, 1 warning (0.00 sec)

+---------+------+---------------------------------+
| Level   | Code | Message                         |
+---------+------+---------------------------------+
| Warning | 1292 | Incorrect datetime value: 'WAT' |
+---------+------+---------------------------------+
1 row in set (0.00 sec)

It's really weird because MySQL became stricter lately...

@casperisfine
Copy link
Contributor

Actually it was already a warning on 5.7, so I don't think this change is the root cause.

Looking at the source, it's the mysql2 gem that raise these errors explictly, that part of the code must be broken.

@casperisfine
Copy link
Contributor

Ok, so on 5.7, the client library do return the string that failed to parse, as in row[i] = "1972-00-27 00:00:00".

On 8.0 however row[i] = NULL.

I'll dig a bit more but I don't think we can actually preserve that old behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants