adelevie / parse-ruby-client

A simple Ruby client for the parse.com REST API
MIT License
415 stars 137 forks source link

Query conditions completely ignored #64

Closed fictorial closed 11 years ago

fictorial commented 11 years ago

With parse-ruby-client 0.1.2 and ruby 1.8.7 on Mac OS X 10.7.5, I am seeing a major issue in which query conditions are ignored.

I adapted one of your unit tests to reduce the issue to its core.

require 'rubygems'
require 'json'
require 'parse-ruby-client'

Parse.init

foo = Parse::Object.new "Post"
foo["random"] = rand
foo.save
foo_query = Parse::Query.new("Post").eq("random", foo["random"])
print "1 == #{foo_query.get.size}\n"

bar = Parse::Object.new "Post"
bar["random"] = rand
bar.save
bar_query = Parse::Query.new("Post").eq("random", bar["random"])
print "1 == #{foo_query.get.size}\n"

query = foo_query.or(bar_query)
print "2 == #{foo_query.get.size}\n"

This is printing

1 == 1
1 == 2 <-- error
2 == 2 

The Post objects on Parse (as per the Data Browser):

objectId     random 
RqfRUhQLF4   0.959963811455423
6oF7tJXjvW   0.754638272517693
adelevie commented 11 years ago

This is odd. Maybe there was a bug in 0.1.2 that has since been fixed? Testing against 0.1.12, this passes:

adelevie@Alans-MacBook-Air:parse-ruby-client → master ruby -Itest test/test_query.rb 
Loaded suite test/test_query
Started
.........

Finished in 1.178536 seconds.

9 tests, 16 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
100% passed

Also, these tests pass fine on Travis.

Are you seeing this problem in one of your own applications? Feel free to email me and show me the problem there if that's easier. I really would like to get to the bottom of this. Thanks for reporting this.

fictorial commented 11 years ago

Sorry, I didn't mean 0.1.2 I meant 0.1.12

Yes, this is one of my own apps but I was able to reproduce it using the above modified unit-test.

In my app/script, the queries are ignored and 100 objects are returned every time. This seems to be the default Parse result-count limit. Setting limit on the query doesn't do anything either.

adelevie commented 11 years ago

If you clone the repo and run rake, do the tests pass? I'm having trouble reproducing this.

Sent from my iPhone

On Feb 4, 2013, at 3:00 PM, Brian Hammond notifications@github.com wrote:

Sorry, I didn't mean 0.1.2 I mean 0.1.12

Yes, this is one of my own apps but I was able to reproduce it using the above modified unit-test.

In my app/script, the queries are ignored and 100 objects are returned every time. This seems to be the default Parse result-count limit. Setting limit on the query doesn't do anything either.

— Reply to this email directly or view it on GitHub.

fictorial commented 11 years ago

Here's the output when I run rake from a clone of this repo:

parse-ruby-client(master) $ rake
WARNING: 'require 'rake/rdoctask'' is deprecated.  Please use 'require 'rdoc/task' (in RDoc 2.4.2+)' instead.
    at /usr/local/rubygems/gems/rake-0.9.2.2/lib/rake/rdoctask.rb
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -I"lib:lib:test" -I"/usr/local/rubygems/gems/rake-0.9.2.2/lib" "/usr/local/rubygems/gems/rake-0.9.2.2/lib/rake/rake_test_loader.rb" "test/**/test_*.rb" 
./test/../lib/parse-ruby-client.rb:11:in `require': no such file to load -- json (LoadError)
    from ./test/../lib/parse-ruby-client.rb:11
    from ./test/helper.rb:24:in `require'
    from ./test/helper.rb:24
    from /Users/bhammond/OpenSource/parse-ruby-client/test/test_batch.rb:1:in `require'
    from /Users/bhammond/OpenSource/parse-ruby-client/test/test_batch.rb:1
    from /usr/local/rubygems/gems/rake-0.9.2.2/lib/rake/rake_test_loader.rb:10:in `require'
    from /usr/local/rubygems/gems/rake-0.9.2.2/lib/rake/rake_test_loader.rb:10
    from /usr/local/rubygems/gems/rake-0.9.2.2/lib/rake/rake_test_loader.rb:9:in `each'
    from /usr/local/rubygems/gems/rake-0.9.2.2/lib/rake/rake_test_loader.rb:9
    from /usr/local/rubygems/gems/rake-0.9.2.2/lib/rake/rake_test_loader.rb:4:in `select'
    from /usr/local/rubygems/gems/rake-0.9.2.2/lib/rake/rake_test_loader.rb:4
rake aborted!
Command failed with status (1): [/System/Library/Frameworks/Ruby.framework/...]

Tasks: TOP => default => test
(See full trace by running task with --trace)
fictorial commented 11 years ago

Of course I tried to install the json gem prior to this but for some reason when I use parse-ruby-client I had to first require 'json' then require 'parse-ruby-client' which your code does not seem (nor need) to do.

parse-ruby-client(master) $ gem install json
Building native extensions.  This could take a while...
Successfully installed json-1.7.6
1 gem installed
Installing ri documentation for json-1.7.6...
Installing RDoc documentation for json-1.7.6...
fictorial commented 11 years ago

OK so that's not true actually looking at parse-ruby-client.rb. So, I'm not sure what's up there.

adelevie commented 11 years ago

Maybe it's a Ruby version issue? On Travis, I'm only testing against 1.9.2 and 1.9.3. This is largely for my sanity, but if upgrading Ruby for you is a no-go, let's keep this issue open and try to figure out what's going on.

fictorial commented 11 years ago

Bah... I installed Ruby 1.9.3 from Homebrew. Now I get this:

[BUG] cross-thread violation on rb_gc() (null)

rake aborted! SIGIOT

adelevie commented 11 years ago

That is...gross. I wish I could guide you on this one, but I'm probably more clueless than you for this.

On Mon, Feb 4, 2013 at 4:01 PM, Brian Hammond notifications@github.comwrote:

Bah... I installed Ruby 1.9.3 from Homebrew. Now I get this:

[BUG] cross-thread violation on rb_gc() (null)

rake aborted! SIGIOT

— Reply to this email directly or view it on GitHubhttps://github.com/adelevie/parse-ruby-client/issues/64#issuecomment-13099173.

fictorial commented 11 years ago

Alright no worries. So my target host platform is Heroku not OS X so I will try this again on a Linux VM soon.

Thanks.

adelevie commented 11 years ago

Cool, let me know how that goes. For what it's worth, I run OS X for developing parse-ruby-client using ruby 1.9.3.

On Mon, Feb 4, 2013 at 4:11 PM, Brian Hammond notifications@github.comwrote:

Alright no worries. So my target host platform is Heroku not OS X so I will try this again on a Linux VM soon.

Thanks.

— Reply to this email directly or view it on GitHubhttps://github.com/adelevie/parse-ruby-client/issues/64#issuecomment-13099656.

fictorial commented 11 years ago

OK I installed Ruby 1.9.3 via RVM.

Problem is still happening:

TourneyRunner(master) $ ruby -v ruby 1.9.3p374 (2013-01-15 revision 38858) [x86_64-darwin11.4.2]

TourneyRunner(master) $ gem -v 1.8.25

TourneyRunner(master) $ gem list

* LOCAL GEMS *

bigdecimal (1.1.0) bundler (1.2.3) io-console (0.3) json (1.7.6, 1.5.4) minitest (2.5.1) parse-ruby-client (0.1.12) patron (0.4.18, 0.4.9) rack (1.5.0) rack-protection (1.3.2) rake (0.9.2.2) rdoc (3.9.4) sinatra (1.3.4) tilt (1.3.3)

TourneyRunner(master) $ pbcopy < test.rb require 'rubygems' require 'json' require 'parse-ruby-client'

Parse.init

foo = Parse::Object.new "Post" foo["random"] = rand foo.save foo_query = Parse::Query.new("Post").eq("random", foo["random"]) print "1 == #{foo_query.get.size}\n"

bar = Parse::Object.new "Post" bar["random"] = rand bar.save bar_query = Parse::Query.new("Post").eq("random", bar["random"]) print "1 == #{foo_query.get.size}\n"

query = foo_query.or(bar_query) print "2 == #{foo_query.get.size}\n"

TourneyRunner(master) $ ruby test.rb 1 == 1 1 == 2 2 == 2

fictorial commented 11 years ago

I moved test.rb to a different directory thinking that perhaps something I am unaware of in the Ruby ecosystem was screwing things up. Sure enough, it worked as expected.

After some trial and error, it seems that the bug is in Patron. I was specifying an old version 0.4.9. How I had that in there I have no idea.

Anyway, thanks.

adelevie commented 11 years ago

That's really odd that it was an issue with the Patron version. Thanks for working through this though.

I hope you enjoy using the gem.

Sent from my iPhone

On Feb 4, 2013, at 9:36 PM, Brian Hammond notifications@github.com wrote:

I moved test.rb to a different directory thinking that perhaps something I am unaware of in the Ruby ecosystem was screwing things up. Sure enough, it worked as expected.

After some trial and error, it seems that the bug is in Patron. I was specifying an old version 0.4.9. How I had that in there I have no idea.

Anyway, thanks.

— Reply to this email directly or view it on GitHub.