Skip to content

Active Storage bug: content_type delegated to attachment, but attachment is nil #8227

@ahukkanen

Description

@ahukkanen

Describe the bug
When entering the initiatives view on the development environment of Decidim (initiated prior to Active Storage feature and migrated with the Active Storage migrations), it will throw this kind of an error.

The system had previous initiatives attachments from CarrierWave and the Decidim upgrade migrations were run after #7598 was merged.

I am not sure if this is still ongoing work as there is still one PR open regarding the Active Storage migration #7902.

To Reproduce
Steps to reproduce the behavior:

  1. Create a Decidim development app with seeds prior to commit merging Active storage migration #7598
  2. Go to the Initiatives view and see that it works properly
  3. Pull in the latest changes including Active storage migration #7598
  4. Run decidim:upgrade and db:migrate
  5. Go to the initiatives view to see that it now crashing

Expected behavior
I would expect the initiatives view to work as it used to.

Screenshots
If applicable, add screenshots to help explain your problem.

Stacktrace

ActionView::Template::Error (content_type delegated to attachment, but attachment is nil):
    1: <%= card_for initiative %>
  
activesupport (6.0.3.7) lib/active_support/core_ext/module/delegation.rb:310:in `rescue in method_missing'
activesupport (6.0.3.7) lib/active_support/core_ext/module/delegation.rb:306:in `method_missing'
/.../dev/rails/decidim/decidim-initiatives/app/cells/decidim/initiatives/initiative_m_cell.rb:69:in `block in image'
activerecord (6.0.3.7) lib/active_record/relation/delegation.rb:87:in `each'
activerecord (6.0.3.7) lib/active_record/relation/delegation.rb:87:in `each'
activerecord (6.0.3.7) lib/active_record/relation/finder_methods.rb:68:in `find'
activerecord (6.0.3.7) lib/active_record/relation/finder_methods.rb:68:in `find'
activerecord (6.0.3.7) lib/active_record/associations/collection_proxy.rb:136:in `find'
/.../dev/rails/decidim/decidim-initiatives/app/cells/decidim/initiatives/initiative_m_cell.rb:68:in `image'
/.../dev/rails/decidim/decidim-initiatives/app/cells/decidim/initiatives/initiative_m_cell.rb:64:in `has_image?'
/.../dev/rails/decidim/decidim-core/app/cells/decidim/card_m/show.erb:5:in `__tilt_200680'
tilt (2.0.10) lib/tilt/template.rb:170:in `call'
tilt (2.0.10) lib/tilt/template.rb:170:in `evaluate'
tilt (2.0.10) lib/tilt/template.rb:109:in `render'
cells (4.1.7) lib/cell/view_model.rb:118:in `render_template'
cells (4.1.7) lib/cell/view_model.rb:110:in `render_to_string'
cells (4.1.7) lib/cell/layout.rb:23:in `render_to_string'
cells (4.1.7) lib/cell/view_model.rb:104:in `render'
/.../dev/rails/decidim/decidim-core/app/cells/decidim/card_m_cell.rb:16:in `show'
...

Extra data (please complete the following information):

  • Device: (any)
  • Device OS: (any)
  • Browser: (any)
  • Decidim Version: current develop branch
  • Decidim installation: development installation

Additional context
It seems that this case happens when:

  • The initiative has an attachment
  • The attachment has a file record (Active Storage)
  • The attachment url is set to nil (I don't know why)
  • It also seems the blob object is not available for these old attachment files, which probably means they haven't been converted to Active Storage blobs yet (and I did not find any migration tool to do that or any documentation/changelog notes about that)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions