Commit 3e178326 authored by Jason Goodman's avatar Jason Goodman Committed by Bob Van Landuyt

Fix Deprecation Warning in has_environment_scope

parent f0830bdf
...@@ -33,8 +33,8 @@ module HasEnvironmentScope ...@@ -33,8 +33,8 @@ module HasEnvironmentScope
order = <<~SQL order = <<~SQL
CASE environment_scope CASE environment_scope
WHEN %{wildcard} THEN 0 WHEN :wildcard THEN 0
WHEN %{environment_name} THEN 2 WHEN :environment_name THEN 2
ELSE 1 ELSE 1
END #{order_direction} END #{order_direction}
SQL SQL
...@@ -44,12 +44,7 @@ module HasEnvironmentScope ...@@ -44,12 +44,7 @@ module HasEnvironmentScope
environment_name: environment_name environment_name: environment_name
} }
quoted_values = values.transform_values do |value| sanitized_order_sql = sanitize_sql_array([order, values])
# Note that the connection could be
# Gitlab::Database::LoadBalancing::ConnectionProxy
# which supports `quote` via `method_missing`
ApplicationRecord.connection.quote(value)
end
# The query is trying to find variables with scopes matching the # The query is trying to find variables with scopes matching the
# current environment name. Suppose the environment name is # current environment name. Suppose the environment name is
...@@ -69,7 +64,7 @@ module HasEnvironmentScope ...@@ -69,7 +64,7 @@ module HasEnvironmentScope
# the exact matched name, and put * last, and everything else in the # the exact matched name, and put * last, and everything else in the
# middle. So the order should be: D < C < B # middle. So the order should be: D < C < B
relation = where(where, values) relation = where(where, values)
.order(order % quoted_values) # `order` cannot escape for us! .order(Arel.sql(sanitized_order_sql)) # `order` cannot escape for us!
relation = relation.limit(1) if relevant_only relation = relation.limit(1) if relevant_only
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment