-
Notifications
You must be signed in to change notification settings - Fork 21.3k
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
Hstore arrays fix (follow up for #11444) #13512
Conversation
if Hash === object | ||
object.map { |k,v| | ||
"#{escape_hstore(k)}=>#{escape_hstore(v)}" | ||
}.join ',' | ||
}.join(',').tap { |s| s.replace escape_hstore(s) if array_member } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO .tap makes things confusing here. Perhaps assign to a variable and operate on it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good. Dropped the tap and force pushed.
Looks like pg tests are green on Travis!!! /cc @senny |
@@ -1,3 +1,10 @@ | |||
* Perform necessary deeper encoding when hstore is inside an array, and return the | |||
hstores as HashWithIndifferentAccess to be consistent with other forms. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm gonna change this since we dropped the indifferent access.
/cc @rafaelfranca |
+1 endorsement by original author, with thanks for picking this up |
+1 |
PR looks good, but it might be better if we extract all the tests to a separate file like array_hstore_test or something like that. |
@carlosantoniodasilva They used to be in a separate file in #11444, but because they had some code duplication, @senny suggested to move them into one file. |
@gsamokovarov my comment also mentioned that most tests are duplication of existing functionality, judging from the patch size, is it necessary to keep all the tests? Isn't most functionality delegated and verified elsewhere already? |
Oh, @senny, I got you now. Sorry for my misunderstanding. Took a look at I did the changes in a separate commit (instead of amending), so you can see exactly what I did. @inopinatus do you think I cut something, that might have been important? |
@@ -1,3 +1,9 @@ | |||
* Perform necessary deeper encoding when hstore is inside an array. | |||
|
|||
Fixes: #11135 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick, can you change the format to: Fixes #11135.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. Found another Fixes: #12345
reference a couple of lines below, so put that into the desired format as well.
@gsamokovarov can you squash your commits together and push a rebased version? |
"#{escape_hstore(k)}=>#{escape_hstore(v)}" | ||
}.join ',' | ||
}.join(',') | ||
string.replace(escape_hstore(string)) if array_member |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there a reason to use string.replace
over string =
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch.
Hey, I squashed this to 2 commits, so the original author still keeps his commit in the history. |
@gsamokovarov please squash the other one as well. You can set him as |
@senny done. |
@rafaelfranca any chance getting this in before |
+1, I've been using a patched version for awhile now waiting for this to get in. |
@senny seems good to me. |
@gsamokovarov I was happy with your update, you didn't cut anything I thought important. And I am not precious about attribution :-). Thanks for running with this, I am distracted by other things right now. Hoping this makes it into 4.0.3. |
@gsamokovarov can you please rebase this and ping us immediately (via CF or IM) to merge it before of getting merge conflicts again? 😄 |
We didn't have enough encoding for the wire protocol to store an array of hstore types. So, further encode any hstore that is an array member. Whilst we're here, ensure it's an HashWithIndifferentAccess being returned, to be consistent with other serialized forms, and add testing for arrays of hstore. So now the following migration: enable_extension "hstore" create_table :servers do |t| t.string :name t.hstore :interfaces, array: true end produces a model that can used like this, to store an array of hashes: server = Server.create(name: "server01", interfaces: [ { name: "bge0", ipv4: "192.0.2.2", state: "up" }, { name: "de0", state: "disabled", by: "misha" }, { name: "fe0", state: "up" }, ]) More at http://inopinatus.org/2013/07/12/using-arrays-of-hstore-with-rails-4/
@guilleiguaran should merge cleanly now :) |
Hstore arrays fix (follow up for #11444)
Backport #13512 to 4.0 stable
I took #11444, rebased it to the current master and addressed @senny comments.
I'm getting the following error locally, and I'm not currently sure if its happening because of the changes:
Using this as a test bed to see if it also fails on Travis :)