Skip to content

Commit

Permalink
Merge pull request #22121 from gocardless/patch-2
Browse files Browse the repository at this point in the history
Set standard_conforming_strings with SET
  • Loading branch information
pixeltrix committed Oct 29, 2015
2 parents 97b3603 + 6a9323b commit a25c2cb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
13 changes: 8 additions & 5 deletions activerecord/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
* Use `UPDATE` rather than `SET` when enabling the `standard_conforming_strings`
setting as this allows us to avoid disabling errors on the PostgreSQL connection.
The former behavior would cause problems when using a connection pooling tool like
PgBouncer because it's not guaranteed to have the same connection between calls to
`execute` and it could leave the connection with errors disabled.
* Avoid disabling errors on the PostgreSQL connection when enabling the
standard_conforming_strings setting. Errors were previously disabled because
the setting wasn't writable in Postgres 8.1 and didn't exist in earlier
versions. Now Rails only supports Postgres 8.2+ we're fine to assume the
setting exists. Disabling errors caused problems when using a connection
pooling tool like PgBouncer because it's not guaranteed to have the same
connection between calls to `execute` and it could leave the connection
with errors disabled.

Fixes #22101.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,13 +281,8 @@ def supports_primary_key? #:nodoc:
true
end

# Enable standard-conforming strings if available.
def set_standard_conforming_strings
execute(<<-SQL, 'SCHEMA')
UPDATE pg_settings
SET setting = 'on'
WHERE name = 'standard_conforming_strings' AND context = 'user'
SQL
execute('SET standard_conforming_strings = on', 'SCHEMA')
end

def supports_ddl_transactions?
Expand Down Expand Up @@ -652,7 +647,7 @@ def configure_connection
self.client_min_messages = @config[:min_messages] || 'warning'
self.schema_search_path = @config[:schema_search_path] || @config[:schema_order]

# Use standard-conforming strings if available so we don't have to do the E'...' dance.
# Use standard-conforming strings so we don't have to do the E'...' dance.
set_standard_conforming_strings

# If using Active Record's time zone support configure the connection to return
Expand Down

0 comments on commit a25c2cb

Please sign in to comment.