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
undefined method `attachment_reflections' for nil:NilClass when removing an entry with Active Storage with variants from console #40962
Comments
Ah - it's because you're using UUID primary keys and the ActiveStorage relations default to integers. See this issue and my fix at the bottom: #40986 |
I had attachment_reflections errors for Nil class as well using rails 6.1. Error was not on deleting but processing variant.
updating imagemagic solved problem (MAC) |
I have this version (1.2) of image_processing and the problem keep going. It looks like @josh-m-sharpe is right and it's related to having UUID as a primary id. It's good to know that not using UUID is a work around, but I wonder if there is an easy fix to this. |
I've fixed this with a migration to remove the class ChangeActiveStorageRecordReferencesToUuid < ActiveRecord::Migration[6.1]
def change
remove_column :active_storage_attachments, :record_id
add_column :active_storage_attachments, :record_id, :uuid, null: false
end
end You could also fix this by adding |
I have decided to stick to default BigInt, but thanks for your help guys. Knowing the reason and an alternative solution is enough for me, but I don't feel 100% safe knowing it could be a source of pain and incompatibilities in the future win gems and integrations so I will take this time the safe road. |
This issue has been automatically marked as stale because it has not been commented on for at least three months. |
Related to #40986 |
this solved it for me. But what if we have one model using |
I had the same problem just now, I applied your resolution and it worked perfectly o/ |
Steps to reproduce
Building a scaffold with an Active Storage image and at least 1 variant in a view throw this error when destroy.
In console it happens everytime, in the browser I have this error 1 time but I haven't been able to reproduce.
All images are still found after destroy in the system
Expected behavior
After detroy the image and its variants should be removed silently and without throwing any error.
Actual behavior
An error is thrown and all the images are still in the folder storage
System configuration
Rails version: 6.1.0
Ruby version: 2.7.2
The text was updated successfully, but these errors were encountered: