Commit 84a491ba authored by Bob Van Landuyt's avatar Bob Van Landuyt

Merge branch 'has-environment-deprecation' into 'master'

Fix Deprecation Warning in has_environment_scope

See merge request gitlab-org/gitlab-ee!14806
parents f0830bdf 3e178326
......@@ -33,8 +33,8 @@ module HasEnvironmentScope
order = <<~SQL
CASE environment_scope
WHEN %{wildcard} THEN 0
WHEN %{environment_name} THEN 2
WHEN :wildcard THEN 0
WHEN :environment_name THEN 2
ELSE 1
END #{order_direction}
SQL
......@@ -44,12 +44,7 @@ module HasEnvironmentScope
environment_name: environment_name
}
quoted_values = values.transform_values do |value|
# Note that the connection could be
# Gitlab::Database::LoadBalancing::ConnectionProxy
# which supports `quote` via `method_missing`
ApplicationRecord.connection.quote(value)
end
sanitized_order_sql = sanitize_sql_array([order, values])
# The query is trying to find variables with scopes matching the
# current environment name. Suppose the environment name is
......@@ -69,7 +64,7 @@ module HasEnvironmentScope
# the exact matched name, and put * last, and everything else in the
# middle. So the order should be: D < C < B
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
......
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