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
The problem is Faraday::HttpCache returns parsed_data with string keys instead of symbols, so klass.extract_array in her/model/parse.rb:171 returns nil because it's looking for :data (but not 'data').
I was able to work around the problem by adding:
def self.extract_array(request_data)
super(request_data.with_indifferent_access)
end
def self.initialize_collection(klass, parsed_data={})
collection_data = klass.extract_array(parsed_data).map do |item_data|
...
her/model/parse.rb:171
def extract_array(request_data)
if request_data[:data].is_a?(Hash) && (active_model_serializers_format? || json_api_format?)
request_data[:data][pluralized_parsed_root_element]
else
request_data[:data]
end
end
The text was updated successfully, but these errors were encountered:
Does Faraday::HttpCache rely on intercepting the request before it's made? It would seem that it should be caching raw HTTP responses before the keys have been symbolized in the first place. scratches head
I believe that it needs to, so it can add the proper Cache-Control headers if it has previously stored the etag. How would I test? By placing Faraday::HttpCache below NetHttp in the middleware stack?
Ah, so after looking at Faraday::HttpCache and the Her docs a little better, I think the issue is that HttpCache is using serialization, and Her is very adamant about the input it receives. The documentation references using FaradayMiddleware::Caching, which doesn't seem to attempt any of this serialization malarky. That might be worth trying instead.
If you would prefer to stick with HttpCache, you could probably just write a custom serializer that piggybacks on JSON and has a call to stringify_keys on the load. I would avoid the Hash#with_indifferent_access for the simple reason that you're handing Her an object that it isn't expecting and you could run into a bug with it.
When I use Faraday::HttpCache in my middleware, cached responses return this error:
The problem is Faraday::HttpCache returns
parsed_data
with string keys instead of symbols, soklass.extract_array
in her/model/parse.rb:171 returns nil because it's looking for:data
(but not'data'
).I was able to work around the problem by adding:
to my class (ActiveSupport::HashWithIndifferentAccess). Should extract_array be modified to accept a string key? I can submit a PR if necessary.
relevant code snippets
My middleware:
her/model/attributes.rb:34
her/model/parse.rb:171
The text was updated successfully, but these errors were encountered: