TL;DR
For "NoMethodError: undefined method 'key?' for #[Faraday::Multipart::CompositeReadIO]": we updated zendeskapi from 1.26 to 1.38.0.rc1 because other dependencies required Faraday >= 2.0. The workaround is to use \id suffixed attributes (send ids only, not whole objects) when you have existing records, since the gem is not exactly like ActiveRecord.
NoMethodError: undefined method 'key?' for #[Faraday::Multipart::CompositeReadIO]
Steps
- We updated zendeskapi from 1.26 to 1.38.0.rc1 because other dependencies required Faraday >= 2.0. Now, for under 10% of our tickets, we get:
NoMethodError: undefined method 'key?' for #[Faraday::Multipart::CompositeReadIO] coming from `zendeskapi/middleware/request/upload.rb in set_file`. It only happens in production and I cannot reproduce it locally. What causes this? - This was a real bug in the rc1 release. It triggered when the request payload was large: users whose ticket payloads carried extra data like thumbnail references got a
Faraday::Multipart::CompositeReadIO instance passed to the upload middleware's set_file, which called key? on it and crashed. The workaround is to use _id suffixed attributes (send ids only, not whole objects) when you have existing records, since the gem is not exactly like ActiveRecord. The actual fix was pushed in the rc2 build, which the maintainer confirmed resolves it. So update to a version containing the rc2 fix, or use the _ids workaround if you are pinned to rc1.
Expected: The actual fix was pushed in the rc2 build, which the maintainer confirmed resolves it.
When to use
You are seeing this: Now, for under 10% of our tickets, we get: NoMethodError: undefined method 'key?' for #[Faraday::Multipart::CompositeReadIO] coming from zendesk\api/middleware/request/upload.rb in set\file. Use this skill when you run into "zendesk_api 1.38.0.rc1 crashes with NoMethodError: undefined method 'key?' on multipart uploads".
When not to use
If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.
Versions
Versions mentioned in the source: zendesk_api 1.38.0. If you are on something much newer or older, the details may have shifted.
Why this happens
We updated zendesk_api from 1.26 to 1.38.0.rc1 because other dependencies required Faraday >= 2.0.