diff --git a/ee/app/finders/geo/attachment_registry_finder.rb b/ee/app/finders/geo/attachment_registry_finder.rb index 447e060ce7ea9313e243265a5ca7f18ede2213a5..b564c31e41a1eea8f3bc547ab3639798f4ef2bdd 100644 --- a/ee/app/finders/geo/attachment_registry_finder.rb +++ b/ee/app/finders/geo/attachment_registry_finder.rb @@ -103,16 +103,23 @@ def group_uploads Namespace.none end - arel_namespace_ids = Arel::Nodes::SqlLiteral.new(namespace_ids.to_sql) + # This query was intentionally converted to a raw one to get it work in Rails 5.0. + # In Rails 5.0 and 5.1 there's a bug: https://github.com/rails/arel/issues/531 + # Please convert it back when on rails 5.2 as it works again as expected since 5.2. + namespace_ids_in_sql = Arel::Nodes::SqlLiteral.new("uploads.model_id IN (#{namespace_ids.to_sql})") - upload_table[:model_type].eq('Namespace').and(upload_table[:model_id].in(arel_namespace_ids)) + upload_table[:model_type].eq('Namespace').and(namespace_ids_in_sql) end def project_uploads project_ids = current_node.projects.select(:id) - arel_project_ids = Arel::Nodes::SqlLiteral.new(project_ids.to_sql) - upload_table[:model_type].eq('Project').and(upload_table[:model_id].in(arel_project_ids)) + # This query was intentionally converted to a raw one to get it work in Rails 5.0. + # In Rails 5.0 and 5.1 there's a bug: https://github.com/rails/arel/issues/531 + # Please convert it back when on rails 5.2 as it works again as expected since 5.2. + project_ids_in_sql = Arel::Nodes::SqlLiteral.new("uploads.model_id IN (#{project_ids.to_sql})") + + upload_table[:model_type].eq('Project').and(project_ids_in_sql) end def other_uploads diff --git a/ee/changelogs/unreleased/rails5-fix-6745.yml b/ee/changelogs/unreleased/rails5-fix-6745.yml new file mode 100644 index 0000000000000000000000000000000000000000..a3dd32009ac740bf585caa52ebde1da078d52c0e --- /dev/null +++ b/ee/changelogs/unreleased/rails5-fix-6745.yml @@ -0,0 +1,5 @@ +--- +title: Rails5 fix AttachmentRegistryFinder arel queries +merge_request: 6396 +author: Jasper Maes +type: fixed