-
Notifications
You must be signed in to change notification settings - Fork 961
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
Empty array becomes an array with a empty string element #494
Comments
We also ran into this issue recently, and seems like in this commit: 7af4154, they allow to use emtpy array as the params, if you provide |
@dotcom900825 thanks for pointing that out. I'll close this since it seems to be fixed. Let me know if I'm misunderstanding. |
@jnunemaker Not understanding your comment. This issue isn't closed and the issue still exists in the latest version. Am I missing something? |
@richkniles ha. Sorry. I guess I am confused too. I thought @dotcom900825 was saying it was fixed, but maybe I read that wrong? |
@jnunemaker |
This just bit us too, and took a while to track down. When params[:object][:nested_objects_attributes] comes in as [""], rather than [ ] as it did in previous versions of httparty, it seems to break activerecord (3.2.22.5) lib/active_record/nested_attributes.rb:421:in `assign_nested_attributes_for_collection_association' -- we get TypeError: no implicit conversion of Symbol into Integer. As a workaround, we'll just do something like
but this was a significant and unexpected behavior change. |
I'm 100% open to a PR with a test for this. I don't need/use this, so I am not sure off hand what people are wanting for a fix. If someone would take a stab at it, that would help. |
Hi, I am also facing this issue when upgrading the Ember. The queryparam when assigned as an empty array becomes an array with an empty string. Is there any solution to this ? |
This issue is still present in v0.16.2. |
I've tested this in other http clients and none of them allow empty arrays. Neither for get, nor for post. I feel like we need to revert changes from #477, because it introduces ambiguity. Now, there no way to distinguish between As for the workarounds, there are couple possibilities here:
|
Just ran into this today. Did this get fixed? Still listed as open |
Not sure how kosher this is, but here's how I got around it:
|
Is this still an issue? I'm using 0.17.3 and encountering this problem. is it fixed AFTER 0.17.3 and should we upgrade? I guess the open question for me is how do you even send an empty array to a REST endpoint now with HTTParty? Are we saying that that isn't supported/shouldn't be supported? |
Yes |
Thanks for the quick response, @TheSmartnik. Any idea what the path forward is on this? It's wreaking havoc with our app trying to upgrade from a frankly very old version of httparty (0.13.7) to something closer to new. We've got two apps basically, a web app in rails and a ruby/cucumber framework that uses it for test metadata I'm trying to convert the body from a hash to json with Previously, when we just sent a hash as the body (hash.with_indifferent_access to be precise) by the time it got to our web app a nil parameter gets converted to an empty string. But when I do explicit So basically out of the frying pan and into the fire, unfortunately. To fix the latter problem (this issue) we now uncovered a new problem that nils aren't being converted to "" when we explicitly send json rather than the hash. Hope that made a modicum of sense. |
Oh, I see. That's unfortunate. If I understand you correctly, sending JSON isn't required, is it? HTTParty.post url, body: params.map { |key, value| value.to_query(key) }.join("&").gsub("%5B%5D=&", "%5B%5D&") Should be parsed correctly by rails servers |
@TheSmartnik This gets rid of nil stuff we don't need to pass and then converts to json. So far that's working for us. Mileage may vary. If we end up finding out it's not working in call cases, I'll try your suggestion. Thanks! |
Is this still something plaguing you? We think we're seeing something like it in a Rails 7 server. |
This is essentially the same issue as rails/rails#30740 |
With httparty 0.14.0 if I I make a POST call like this
HTTParty.post 'http://localhost:3000/somepath', body: {my_param: []}
then at the other end I receivemy_param
with value[""]
while with version 13.0.3 it still remains an empty array. Is this intended behavior in 0.14.0 or is this a bug?The text was updated successfully, but these errors were encountered: