Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • T torque-postgresql
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 6
    • Issues 6
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 1
    • Merge requests 1
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Carlos
  • torque-postgresql
  • Issues
  • #60
Closed
Open
Issue created Apr 26, 2021 by Administrator@rootContributor

deduplicated: undefined method '-@' for []:Array with Rails 6.1 and arrays with default value

Created by: 4ndv

Here's test code:

# frozen_string_literal: true

require "bundler/inline"

gemfile(true) do
  source "https://rubygems.org"

  git_source(:github) { |repo| "https://github.com/#{repo}.git" }

  # Activate the gem you are reporting the issue against.
  gem "activerecord", "6.1.0"
  gem "torque-postgresql"
  gem "pg"
end

require "active_record"
require "logger"

ActiveRecord::Base.establish_connection(
  adapter:  "postgresql",
  database: "torque_pg_test",
  encoding: "unicode",
  host:     "localhost",
  port:     "5432",
  password: "postgres",
  username: "postgres"
)

ActiveRecord::Schema.define do
  drop_table "employees" if table_exists?("employees")
  drop_table "projects" if table_exists?("projects")

  create_table "employees" do |t|
    t.string "name"
    t.timestamps
  end

  create_table "projects" do |t|
    t.bigint "employees_ids", array: true, default: []
    t.string "title"
    t.timestamps
  end
end

class Employee < ActiveRecord::Base
end

class Project < ActiveRecord::Base
  belongs_to_many :employees, foreign_key: :employees_ids
end

Project.inspect

Notice array: true, default: [] in t.bigint "employees_ids", array: true, default: []

When calling Project.inspect since Rails 6.1 there is an exception in AR:

lib/active_record/connection_adapters/column.rb:94:in `deduplicated': undefined method `-@' for []:Array (NoMethodError)

Looks like AR now tries to unfreeze @default, which cannot be done to an Array

Assignee
Assign to
Time tracking