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

Histories don't work when note has attachments #94

Open
madleech opened this issue Mar 27, 2015 · 4 comments
Open

Histories don't work when note has attachments #94

madleech opened this issue Mar 27, 2015 · 4 comments
Labels

Comments

@madleech
Copy link

If a party has a note with attachments, then running CapsuleCRM::Organization.find(<id>).histories generates the following error:

NoMethodError: Expected [{"id"=>"31511119", "filename"=>"005_550.jpg", "contentType"=>"image/jpeg"}, {"id"=>"31511120", "filename"=>"Airvan1.jpg", "contentType"=>"image/jpeg"}, {"id"=>"31511121", "filename"=>"airsafaris-2nomads-5.jpg", "contentType"=>"image/jpeg"}, {"id"=>"31511122", "filename"=>"L.Tekapo_-_Cass_River.jpg", "contentType"=>"image/jpeg"}, {"id"=>"31511123", "filename"=>"N24_at_QN.JPG", "contentType"=>"image/jpeg"}, {"id"=>"31511124", "filename"=>"Logo_snowed.jpg", "contentType"=>"image/jpeg"}] to respond to #to_hash
        from .../vendor/bundle/ruby/2.2.0/gems/virtus-1.0.5/lib/virtus/attribute_set.rb:196:in `coerce'
        from .../vendor/bundle/ruby/2.2.0/gems/virtus-1.0.5/lib/virtus/attribute_set.rb:170:in `set'
        from .../vendor/bundle/ruby/2.2.0/gems/virtus-1.0.5/lib/virtus/instance_methods.rb:17:in `initialize'
        from .../vendor/bundle/ruby/2.2.0/gems/capsule_crm-1.10.3/lib/capsule_crm/associations/has_many_association.rb:83:in `new'
        from .../vendor/bundle/ruby/2.2.0/gems/capsule_crm-1.10.3/lib/capsule_crm/associations/has_many_association.rb:83:in `collection_to_array'
        from .../vendor/bundle/ruby/2.2.0/gems/capsule_crm-1.10.3/lib/capsule_crm/associations/has_many_association.rb:78:in `build_target'
        from .../vendor/bundle/ruby/2.2.0/gems/capsule_crm-1.10.3/lib/capsule_crm/associations/has_many_association.rb:42:in `proxy'
        from .../vendor/bundle/ruby/2.2.0/gems/capsule_crm-1.10.3/lib/capsule_crm/associations/has_many.rb:62:in `block in has_many'
        from .../vendor/bundle/ruby/2.2.0/gems/virtus-1.0.5/lib/virtus/attribute_set.rb:173:in `block in set'
        from .../vendor/bundle/ruby/2.2.0/gems/virtus-1.0.5/lib/virtus/attribute_set.rb:170:in `each'
        from .../vendor/bundle/ruby/2.2.0/gems/virtus-1.0.5/lib/virtus/attribute_set.rb:170:in `set'
        from .../vendor/bundle/ruby/2.2.0/gems/virtus-1.0.5/lib/virtus/instance_methods.rb:17:in `initialize'
        from .../vendor/bundle/ruby/2.2.0/gems/capsule_crm-1.10.3/lib/capsule_crm/normalizer.rb:72:in `new'
        from .../vendor/bundle/ruby/2.2.0/gems/capsule_crm-1.10.3/lib/capsule_crm/normalizer.rb:72:in `block in normalize_standard_collection'
        from .../vendor/bundle/ruby/2.2.0/gems/capsule_crm-1.10.3/lib/capsule_crm/normalizer.rb:68:in `map'
        from .../vendor/bundle/ruby/2.2.0/gems/capsule_crm-1.10.3/lib/capsule_crm/normalizer.rb:68:in `normalize_standard_collection'
        from .../vendor/bundle/ruby/2.2.0/gems/capsule_crm-1.10.3/lib/capsule_crm/normalizer.rb:18:in `normalize_collection'
        from .../vendor/bundle/ruby/2.2.0/gems/capsule_crm-1.10.3/lib/capsule_crm/associations/belongs_to_finder.rb:34:in `find_by_parent_id'
        from .../vendor/bundle/ruby/2.2.0/gems/capsule_crm-1.10.3/lib/capsule_crm/associations/belongs_to_finder.rb:12:in `call'
        from .../vendor/bundle/ruby/2.2.0/gems/capsule_crm-1.10.3/lib/capsule_crm/associations/belongs_to.rb:46:in `block (2 levels) in belongs_to'
        from .../vendor/bundle/ruby/2.2.0/gems/capsule_crm-1.10.3/lib/capsule_crm/associations/has_many_association.rb:93:in `target'
        from .../vendor/bundle/ruby/2.2.0/gems/capsule_crm-1.10.3/lib/capsule_crm/associations/has_many_association.rb:78:in `build_target'
        from .../vendor/bundle/ruby/2.2.0/gems/capsule_crm-1.10.3/lib/capsule_crm/associations/has_many_association.rb:42:in `proxy'
        from .../vendor/bundle/ruby/2.2.0/gems/capsule_crm-1.10.3/lib/capsule_crm/associations/has_many.rb:57:in `block in has_many'

To recreate, set up an organization, then in CapsuleCRM create a note with file attachments.

@mattbeedle mattbeedle added the bug label Mar 27, 2015
@ioquatix
Copy link

ioquatix commented May 8, 2015

+1 having this issue too.

@mattbeedle
Copy link
Owner

Is this still an issue? I'm trying to replicate in a test app but it seems to be working fine. I'm adding 2 notes each with an attachment to an organisation in the capsule UI and then fetching them with the gem.

@madleech
Copy link
Author

I think it only happens with > 1 attachment. It is still an issue, of sorts. I solved it with this mixin:

module Virtus
    class AttributeSet
        def coerce(attributes)
            if attributes.is_a? Array
                keys = {}
                self.each_with_index{|item, index| keys[index.to_s] = item.to_hash if item.respond_to? :to_hash }
                keys
            else
                ::Hash.try_convert(attributes) or raise(
                    NoMethodError, "Expected #{attributes.inspect} to respond to #to_hash"
                )
            end
        end
    end
end

... but it would be good to solve the root issue too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants
@mattbeedle @ioquatix @madleech and others