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

Stop explicitly setting sql_auto_is_null #44739

Closed

Conversation

HParker
Copy link
Contributor

@HParker HParker commented Mar 21, 2022

Fixes: #44667

Since version 5.5 the default has been off which is the minimum supported mysql version.

@yahonda
Copy link
Member

yahonda commented Mar 22, 2022

Even if the default value of sql_auto_is_null changed to 0 at some MySQL version,
Some users may set sql_auto_is_null value to non-zero at somewhere like my.cnf

So I think it needs to check the current setting of sql_auto_is_null first as follows.

variables["sql_auto_is_null"] = 0 unless query_value('select @@sql_auto_is_null') == 0

@HParker
Copy link
Contributor Author

HParker commented Mar 22, 2022

@yahonda my understanding from the issue is that setting the variable at all causes RDS to change its connection behavior regardless of the value it is set to.

If you know a way to unset a variable, we can recommend that instead, though I am not sure how valuable keeping this would be even in that case since it is the default value on all rails supported MySQL versions.

@HParker
Copy link
Contributor Author

HParker commented Mar 22, 2022

Oh, no I understand sorry, you are saying if the variable was set manually we still need to override it if they did, but only if they did. Thanks! I like that idea. I'll add that right away!

@HParker HParker force-pushed the stop-explicitly-setting-sql_auto_is_null branch from 9aef40e to 66cb4a3 Compare March 22, 2022 15:41
@yahonda
Copy link
Member

yahonda commented Mar 22, 2022

you are saying if the variable was set manually we still need to override it if they did, but only if they did.

Yes. I mean to say that. I do not know how many users set sql_auto_is_null to 1 manually but just in case.

@HParker
Copy link
Contributor Author

HParker commented Mar 23, 2022

Hmm, I am confused by this error. Maybe since we are still setting up the connection we can't query this value yet?

@@ -787,8 +787,8 @@ def supports_rename_column?
def configure_connection
variables = @config.fetch(:variables, {}).stringify_keys

# By default, MySQL 'where id is null' selects the last inserted id; Turn this off.
variables["sql_auto_is_null"] = 0
# Since MySQL 5.5 sql_auto_is_null is off by default, but if it is set for any reason, we need to turn it off.
Copy link

@xiankaing xiankaing Mar 23, 2022

Choose a reason for hiding this comment

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

do we really need force it off?
is it to semi-preserve existing behavior?

seems to me appropriate that rails not override an explicit setting by a user saying he wants to get the last item written if he queries for id is null

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I believe for most users where id is null returning the last inserted record would be surprising behavior.

@HParker HParker changed the title Stop explicitly settign sql_auto_is_null Stop explicitly setting sql_auto_is_null Apr 27, 2022
Since version 5.5 the default has been off by default, this change explicitly sets the variable if it is already set.
@HParker HParker force-pushed the stop-explicitly-setting-sql_auto_is_null branch from a89b2d2 to 9e87228 Compare May 4, 2022 20:16
@HParker
Copy link
Contributor Author

HParker commented May 4, 2022

Updated and rebased back to one commit just in case.

# By default, MySQL 'where id is null' selects the last inserted id; Turn this off.
variables["sql_auto_is_null"] = 0
# Since MySQL 5.5 sql_auto_is_null is off by default, but if it is set for any reason, we need to turn it off.
variables["sql_auto_is_null"] = 0 unless query_value("select @@sql_auto_is_null") == 0
Copy link
Member

Choose a reason for hiding this comment

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

I get that people may have flipped this config, but honestly I think it's unlikely, and for the very rare people who did that, we should probably recommend to add this to their database.yml.

I'd rather make it a bit harder to config for these theoretical people, than add an extra query on connect for everyone.

@HParker
Copy link
Contributor Author

HParker commented May 19, 2022

I agree with @byroot that adding a query probably isn't worth it. I also think I don't know enough about this theoretical RDS Proxy user to know what decisions make sense for them. I'll close, but I encourage @xiankaing or anyone who ran into this issue and has more knowledge to open a similar PR.

@HParker HParker closed this May 19, 2022
@HParker HParker deleted the stop-explicitly-setting-sql_auto_is_null branch May 19, 2022 15:13
@casperisfine
Copy link
Contributor

@HParker I was suggesting to remove variables["sql_auto_is_null"] = 0 entirely.

@HParker HParker restored the stop-explicitly-setting-sql_auto_is_null branch May 19, 2022 16:32
@HParker
Copy link
Contributor Author

HParker commented May 19, 2022

Cool, I am happy with that solution as well. I force pushed so GitHub is requiring me to make a new PR: #45134

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

Successfully merging this pull request may close these issues.

stop explicitly setting sql_auto_is_null to zero
6 participants