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

PostgreSQL adapter sets invalid value "panic" for client_min_messages #1085

Open
bblack opened this issue Mar 2, 2021 · 1 comment
Open

Comments

@bblack
Copy link

bblack commented Mar 2, 2021

This has been a problem for us from 50.0 all the way up to 52.7. I see from the source in 60.x this may not be an issue anymore.

The postgresql docs (for pg versions that support client_min_messages, i.e. 10 through 13) specify the valid values for client_min_messages:

Valid values are DEBUG5, DEBUG4, DEBUG3, DEBUG2, DEBUG1, LOG, NOTICE, WARNING, and ERROR.

Yet, the postgres adapter here (up to 52.7 at least) tries setting it to "panic":

# Enable standard-conforming strings if available.
def standard_conforming_strings=(enable)
client_min_messages = self.client_min_messages
begin
self.client_min_messages = 'panic'
value = enable ? "on" : "off"
execute("SET standard_conforming_strings = #{value}", 'SCHEMA')
@standard_conforming_strings = ( value == "on" )
rescue
@standard_conforming_strings = :unsupported
ensure
self.client_min_messages = client_min_messages
end
end

def standard_conforming_strings?
if @standard_conforming_strings.nil?
client_min_messages = self.client_min_messages
begin
self.client_min_messages = 'panic'
value = select_one('SHOW standard_conforming_strings', 'SCHEMA')['standard_conforming_strings']
@standard_conforming_strings = ( value == "on" )
rescue
@standard_conforming_strings = :unsupported
ensure
self.client_min_messages = client_min_messages
end
end
@standard_conforming_strings == true # return false if :unsupported
end

In our app this didn't actually present a problem until we upgraded postgres to either 11 or 12 (we're on 12 now), so perhaps "panic" actually was an acceptable value in a prior version, despite the docs. In any case, it's not an acceptable value now.

The effect is that trying to set it to "panic" raises an error, which is rescued, and @standard_conforming_strings is incorrectly set to :unsupported, which causes problems later when our app constructs properly-escaped queries.

We've worked around it by monkeypatching these functions to remove the extra bits:

module ArJdbc
  module PostgreSQL
    def standard_conforming_strings=(enable)
      value = enable ? "on" : "off"
      execute("SET standard_conforming_strings = #{value}", 'SCHEMA')
      @standard_conforming_strings = ( value == "on" )
    end

    def standard_conforming_strings?
      value = select_one('SHOW standard_conforming_strings', 'SCHEMA')['standard_conforming_strings']
      @standard_conforming_strings = ( value == "on" )
    end
  end
end

As I said, it looks like this may be fixed in 60.x. Can this be backported to 52.x (or further)?

@bblack
Copy link
Author

bblack commented Mar 2, 2021

This has been a problem for us from 50.0 all the way up to 52.7. I see from the source in 60.x this may not be an issue anymore.

Actually, this was a problem before 50.x when we were on Rails 4 too.

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

No branches or pull requests

1 participant