Skip to content
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

Merged
merged 1 commit into from Feb 16, 2014

Conversation

gsamokovarov
Copy link
Contributor

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:

  1) Error:
TimestampTest#test_bc_timestamp:
ActiveRecord::StatementInvalid: PG::DatetimeFieldOverflow: ERROR:  date/time field value out of range: "0000-01-01 07:52:57.000000 BC"
: INSERT INTO "developers" ("created_at", "created_on", "name", "updated_at", "updated_on") VALUES ($1, $2, $3, $4, $5) RETURNING "id"
    /vagrant/rails/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb:818:in `get_last_result'
   ...

Using this as a test bed to see if it also fails on Travis :)

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 }
Copy link
Contributor

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

Copy link
Contributor Author

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.

@guilleiguaran
Copy link
Member

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.
Copy link
Contributor Author

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.

@guilleiguaran
Copy link
Member

/cc @rafaelfranca

@inopinatus
Copy link
Contributor

+1 endorsement by original author, with thanks for picking this up

@ghost ghost assigned rafaelfranca Jan 20, 2014
@hilem
Copy link

hilem commented Jan 23, 2014

+1

@inopinatus
Copy link
Contributor

@senny please consider for merge, this one's been going over six months now but current PR appears to address all your remarks from #11444

@carlosantoniodasilva
Copy link
Member

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.

@gsamokovarov
Copy link
Contributor Author

@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.

@senny
Copy link
Member

senny commented Feb 3, 2014

@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?

@gsamokovarov
Copy link
Contributor Author

Oh, @senny, I got you now. Sorry for my misunderstanding.

Took a look at array_test.rb and removed the similar tests. Do you think we can actually move the new tests we have to array_test.rb as we're duplicating assert_array_cycle?

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
Copy link
Member

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.

Copy link
Contributor Author

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.

@senny
Copy link
Member

senny commented Feb 13, 2014

@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
Copy link
Member

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 = ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch.

@gsamokovarov
Copy link
Contributor Author

Hey, I squashed this to 2 commits, so the original author still keeps his commit in the history.

@senny
Copy link
Member

senny commented Feb 13, 2014

@gsamokovarov please squash the other one as well. You can set him as author and yourself as committer to give credits to both. Having a single commit makes the history more clear and possible reverts and backports more straight forward.

@gsamokovarov
Copy link
Contributor Author

@senny done.

@senny
Copy link
Member

senny commented Feb 13, 2014

@rafaelfranca any chance getting this in before 4.0.3 release?

@hilem
Copy link

hilem commented Feb 14, 2014

+1, I've been using a patched version for awhile now waiting for this to get in.

@rafaelfranca
Copy link
Member

@senny seems good to me. :shipit:

@inopinatus
Copy link
Contributor

@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.

@guilleiguaran
Copy link
Member

@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/
@gsamokovarov
Copy link
Contributor Author

@guilleiguaran should merge cleanly now :)

guilleiguaran added a commit that referenced this pull request Feb 16, 2014
@guilleiguaran guilleiguaran merged commit 7c32db1 into rails:master Feb 16, 2014
guilleiguaran added a commit that referenced this pull request Feb 16, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants