You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If caching is on and the collection which is rendered contains only one element, I get an empty JSON repsonse in some cases. I have these three templates in my Rails 3.2 application:
The message.rabl template is always rendered first. This works fine, I get the json reponse including a node containing one file_share. However, if the file_shares.rabl is rendered in the next request, I get an empty json response.
When the file_shares.rabl is rendered, the extends method gets a cache hit on:
rabl/drive/file_shares/1012-20130620132506//hash
However, the result of that cache hit is an array containing a hash of the file_share. But an array is not what the extends method expects:
lib/rabl/builder.rb:118:
# Extends an existing rabl template with additional attributes in the block# extends("users/show") { attribute :full_name }defextends(file,options={}, &block)options=@options.slice(:child_root).merge(:object=>@_object).merge(options)result=self.partial(file,options, &block)@_result.merge!(result)ifresult.is_a?(Hash)end
The result from self.partial is not a hash, which results in an empty response. However, I think the cause of this bug is in the construction of the cache key in the Rabl engine:
The cache_key variable contains either an object or a collection of objects. However, by using Array(cache_key) the result_cache_key for one object is equal to the result_cache_key for the same object used as the sole object in an array.
If caching is on and the collection which is rendered contains only one element, I get an empty JSON repsonse in some cases. I have these three templates in my Rails 3.2 application:
message.rabl
file_shares.rabl
file_share.rabl
The message.rabl template is always rendered first. This works fine, I get the json reponse including a node containing one file_share. However, if the file_shares.rabl is rendered in the next request, I get an empty json response.
When the file_shares.rabl is rendered, the extends method gets a cache hit on:
rabl/drive/file_shares/1012-20130620132506//hash
However, the result of that cache hit is an array containing a hash of the file_share. But an array is not what the extends method expects:
lib/rabl/builder.rb:118:
The result from self.partial is not a hash, which results in an empty response. However, I think the cause of this bug is in the construction of the cache key in the Rabl engine:
lib/rabl/engine.rb:277
The cache_key variable contains either an object or a collection of objects. However, by using Array(cache_key) the result_cache_key for one object is equal to the result_cache_key for the same object used as the sole object in an array.
A possible solution could be to add information about whether the cache key is for an object or for a collection into the result_cache_key:
I don't know how to create a failing test case for this in the Rabl test suite. If anyone can, I'd love to help solve this issue.
The text was updated successfully, but these errors were encountered: