-
Notifications
You must be signed in to change notification settings - Fork 64
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
cast from Array(String) to String failed from Avram::Params #884
Comments
Ok, it turns out it's here Lines 29 to 31 in 9c8caec
I'm just saying that the avram/src/avram/add_column_attributes.cr Lines 24 to 26 in 9c8caec
when we merge them, if the nested_arrays is the raw hash, then it overrides the Kinda like doing |
So it seems that this doesn't affect normal operations... This seems to work fine: params = Avram::Params({"username" => ["tacoguy"]})
SignInUser.run(params) do |_,_|
end |
I'm running into the same issue. If it helps, here a trace:
|
To get around this for now, I just inherited from # TODO: https://github.com/luckyframework/avram/issues/884
class GraphParams < Avram::Params
def nested?(key : String) : Hash(String, String)
@hash.select(&.ends_with?("[]").!).transform_values(&.first)
end
def nested_arrays?(key : String) : Hash(String, Array(String))
@hash.select(&.ends_with?("[]")).transform_keys(&.chomp("[]"))
end
end
GraphParams.new({
"username" => ["tacoguy"],
"meats[]" => ["pollo", "carne"]
}) It's a bit wonky having to add |
This seems to fix it:
I haven't tested this with the specs though, just fiddling with code in my |
avram/src/avram/add_column_attributes.cr Line 24 in 9c8caec
This should probably change too, to return an array with a single element: single_values = @params.nested(self.class.param_key).reject {|k,v| k.ends_with?("[]")}.transform_values { |value| [value] } And, just a question, shouldn't the |
``` cast from Array(String) to String failed ``` Fixes luckyframework#884.
In #847 I had to change
Avram::Params
to takeHash(String, Array(String))
instead ofHash(String, String)
so that we can allow array params to be passed in. This also aligns withURI::Params
.I wasn't able to make it a union because this caused a LOT of compiler headache trying to determine which type a value was, and constantly having to cast it.
To use this, you would do
As it turns out, the specs never caught this because in the specs, we just inherit from Avram::Params
avram/spec/avram/params_spec.cr
Lines 21 to 37 in 9c8caec
The error actually borks on
avram/src/avram/add_column_attributes.cr
Line 17 in 9c8caec
because in this case,
value
isArray(String)
even though the column should just beString
. The tricky part istypeof(value)
here is actuallyArray(String) | String
which ends up coming back to the original union issue. We need some sort of way to say that if value gets to this branch, and value is still an array, it needs to call.first
, but if it's not an array, then make sure to cast as a String.The text was updated successfully, but these errors were encountered: