Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding array enum column in same migration as enum creation fails with "TypeError: can't quote Array" #58

Open
anaulin opened this issue Jul 14, 2022 · 2 comments
Labels
bug Something isn't working

Comments

@anaulin
Copy link

anaulin commented Jul 14, 2022

Describe the bug
The following migration:

def change
  create_enum :product_type, %w[one-off subscription]

  add_column :products, :types, :product_type, array: true, default: []
end

Fails with the error:

TypeError: can't quote Array

However, separating the create_enum into its own migration, running it, and then separately running a migration with add_column succeeds. (Running the two migrations together also fails.)

I did some exploration, and it seems the problem is that Rails doesn't know the type of the :types column when it is trying to serialize the default value for that column. If I rewrite the above migration as:

  create_enum :product_type, %w[one-off subscription]

  add_column :products, :types, :product_type, array: true

  Product.reset_column_information
  change_column_default :products, :types, default: []

This fails with the errors:

unknown OID 697877: failed to recognize type of 'types'. It will be treated as String.
rails aborted!
StandardError: An error has occurred, this and all later migrations canceled:

can't quote Hash

Expected behavior
I would expect this migration to work without having to first fully apply the create_enum line.

Context (please complete the following information):

  • OS: Debian GNU/Linux 11 (bullseye)
  • Rails 6.1.6.1
  • activerecord-postgres_enum (2.0.1)
  • postgres:13.5
@bibendi bibendi added the bug Something isn't working label Jul 14, 2022
@bibendi
Copy link
Owner

bibendi commented Jul 14, 2022

Thank you for the report!

@anaulin
Copy link
Author

anaulin commented Jul 18, 2022

(Added some more details to description, from my own debugging.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants