cloudinary / cloudinary/cloudinary_gem

Photo metadata is nil until after AR callbacks have run

Open
#499 7 comments 0 reactions 1 assignee Claimed by @tommyg-cld View on GitHub
Dominant language
Ruby
Stars
420
Forks
285
PR merge metrics
No merged PRs in 30d

Description

## Describe the bug in a sentence or two.
I'm trying to extract colors from an uploaded image, [following the docs](https://support.cloudinary.com/hc/en-us/articles/202519912-How-to-get-an-image-s-EXIF-information-using-CarrierWave-) on utilizing `cloudinary_transformation` and an `after_save` on the model. Unfortunately, `metadata` seems to always be `nil`. Once the `after_save` callback has finished, then `source.metadata` is populated. This seems like a misplaced lifecycle callback or something.

## Issue Type (Can be multiple)
- [ ] Build - Cannot install or import the SDK
- [ ] Performance - Performance issues
- [x] Behaviour - Functions are not working as expected (such as generate URL)
- [x] Documentation - Inconsistency between the docs and behaviour
- [ ] Other (Specify)

## Steps to reproduce

```ruby
class PhotoUploader < CarrierWave::Uploader::Base
include Cloudinary::CarrierWave
cloudinary_transformation image_metadata: true, colors: true
end

class Photo < ApplicationRecord
mount_uploader :source, PhotoUploader

after_save :extract_colors

def extract_colors
# `source.metadata` is `nil`
end
end
```

## Environment and Libraries (fill in the version numbers)
- Cloudinary Ruby SDK version - 1.23.0
- Ruby Version - 3.1.2
- Rails Version - 7.0.4
- Carrierwave - 2.2.2

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.