Skip to content
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

Update DATETIME casting tests for mysql 8.0 #1221

Conversation

casperisfine
Copy link
Contributor

Fix: #1208

With Mysql 5, the invalid datetime was returned.

However with 8.0 the returned row is NULL, so we can no longer detect this case and raise.

NB: I chose not to change the behavior on 5.x, but we could also chose to change it to match 8.0 behavior. However I don't see any way to bring back that behavior on 8.0 because it's impossible to distinguish between a NULL datetime and an invalid one.

With Mysql 5, the invalid datetime was returned.

However with 8.0 the returned row is `NULL`, so we can
no longer detect this case and raise.
@casperisfine casperisfine force-pushed the mysql8-update-datetime-casting-error-tests branch from 95d9695 to d79638e Compare November 29, 2021 09:41
@tenderlove tenderlove merged commit 2b0a831 into brianmario:master Nov 30, 2021
@tenderlove tenderlove deleted the mysql8-update-datetime-casting-error-tests branch November 30, 2021 19:16
@sodabrew
Copy link
Collaborator

Thanks!

@@ -410,8 +410,13 @@
end

it "should raise an error given an invalid DATETIME" do
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")
if @client.info[:version] < "8.0"
Copy link
Contributor

@junaruga junaruga Dec 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I seems that this part and another part on this PR to compare the MySQL client version will not work when the MySQL 10.0 is released in the future. The following way could be the solution.

if (@client.info[:version].split('.').map(&:to_i) <=> [8, 0]) < 0

The version is about MySQL not about Gem's, but the following way could be also possible technically.

if Gem::Version.new(@client.info[:version]) < Gem::Version.new("8.0")

I have not tested it by myself.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To best honest it's test code, so it's not like it's gonna break apps updating or anything and we can always update it when we add MySQL 10 to the CI in 4 or 5 years.

But yeah, feel free to PR the Gem::Version one.

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 this pull request may close these issues.

tests: Invalid DATETIME test fails with mysql >= 8.0.24
5 participants