Closed 34code closed 7 years ago
if you do u.reload; p u
, do you see that it's updated?
nope it doesn't update.. same old zipcode. I tested this on another different mac this time. Same issue.. perhaps its the rethinkdb version?
it returns "true" though.. and the console output is in red (meaning its writing)
I also see a spike in cluster performance "writes" graph in the web-ui for my local rethinkdb instance.. but no persistence into the db :(
nobrainer used = nobrainer (0.33.0)
@34code can you provide a self-contained test so I can reproduce the issue? Something along these lines: https://github.com/nviennot/nobrainer/issues/220#issuecomment-233541287
ok working on that script
I don't have your Gemfile + Gemfile.lock to run with.
Can you only include the gems required to run your test? Also, do you need devise to show the bug? if not, take it out.
let me try with devise disabled.. not sure what the root cause is yet
I confirmed the issue still exists when I'm not using devise-nobrainer
and devise
in my rails app
Please write a test that only depends on nobrainer (not rails, sinatra and other stuff). Thank you :)
wait, you did. nvm (I was seeing so much garbage in the Gemfile.lock..., I'll just ignore the Gemfile)
/home/pafy/.rvm/gems/ruby-2.3.3/gems/nobrainer-0.33.0/lib/no_brainer/document/attributes.rb:48:in
write_attribute': undefined method confirmation_sent_at=' for #<User:0x000000020538c0> (NoMethodError)
confirmation_sent_at
is not a defined. Have you tested the script you sent me?
not the new one (I think I had too many dependencies in the Gemfile).. wait let me remove rails and other stuff from the gemfile and test it locally before sending
ok here is a working script.. so this tells me its not a nobrainer issue but likely something with devise/rails and nobrainer working together..
as I'm seeing the expected results in the rethinkdb webUI
require 'awesome_print'
require 'nobrainer'
NoBrainer.configure do |c|
c.app_name = "issue235"
c.environment = "development"
c.logger = Logger.new(STDERR).tap { |l| l.level = Logger::DEBUG }
end
class User
include NoBrainer::Document
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
include ActiveModel::SecurePassword
attr_accessor :activation_token, :reset_token
field :user_id
field :name
field :password_digest
field :password
field :activated, type: Boolean
field :activated_at, type: Time
field :activation_sent_at, type: Time
field :address_line1
field :address_line2
field :address_city
field :address_state
field :address_zipcode
field :address_phone
validates :name, presence: true, length: { maximum: 50 }
validates :address_line1, presence: true, length: { maximum: 50 }
validates :address_line2, presence: true, length: { maximum: 50 }
validates :address_city, presence: true, length: { maximum: 50 }
validates :address_state, presence: true, length: { maximum: 5, minimum: 2 }
validates :address_zipcode, presence: true, length: { maximum: 7 }
validates :address_phone, presence: true, length: { maximum: 14 }
end
user1 = User.create(
address_city: "San Francisco" ,
address_line1: "8900 7th street" ,
address_line2: "2457" ,
address_phone: "637535346" ,
address_state: "CA" ,
address_zipcode: "94103" ,
name: "sambit behera" ,
user_id: "d3b67d6f-de23-40c2-8939-0350a5ac0438-2"
)
user1.update(address_zipcode: "99999")
user2 = User.where(address_zipcode: "99999").first
ap user2
"so this tells me its not a nobrainer issue" wait, so your script does not reproduce your issue? then why do you give it to me? If the bug involves devise, include devise, and show a script that exhibit a bug.
For the record, the latest script does this here:
I, [2017-02-13T21:54:26.821625 #31277] INFO -- : Connected to rethinkdb://localhost:28015/issue235_development
D, [2017-02-13T21:54:26.872764 #31277] DEBUG -- : [ 0.7ms] r.db_create("issue235_development")
D, [2017-02-13T21:54:27.569364 #31277] DEBUG -- : [ 661.2ms] r.table_create( "users", {"durability" => "hard", "shards" => 1, "replicas" => 1, "primary_key" => "id"})
D, [2017-02-13T21:54:27.572002 #31277] DEBUG -- : [ 2.0ms] r.table("users").config.update({"write_acks" => "majority"})
D, [2017-02-13T21:54:27.574383 #31277] DEBUG -- : [ 1.8ms] r.table("users").insert( {"address_city" => "San Francisco", "address_line1" => "8900 7th street", "address_line2" => "2457", "address_phone" => "637535346", "address_state" => "CA", "address_zipcode" => "94103", "name" => "sambit behera", "user_id" => "d3b67d6f-de23-40c2-8939-0350a5ac0438-2", "id" => "4R0qRC6FQomq0z"})
D, [2017-02-13T21:54:27.577460 #31277] DEBUG -- : [ 1.4ms] r.table("users").get("4R0qRC6FQomq0z").update {|var_1| {"address_zipcode" => "99999"}}
I, [2017-02-13T21:54:27.580688 #31277] INFO -- : [ 1.6ms] r.table("users").order_by({"index" => r.asc(:id)}).filter {|var_2| var_2[:address_zipcode].eq("99999")}.limit(1) -- perf: filtering without using an index
#<User id: "4R0qRC6FQomq0z", user_id: "d3b67d6f-de23-40c2-8939-0350a5ac0438-2", name: "sambit behera", address_line1: "8900 7th street", address_line2: "2457", address_city: "San Francisco", address_state: "CA", address_zipcode: "99999", address_phone: "637535346">
devise-nobrainer-issue.zip ok so I'm pretty confident this is an integration issue with rails/devise-nobrainer/devise and the nobrainer gem
I've attached a test project. The user model has the relevant code (user.rb) file..
steps to reproduce:
1> bundle install 2> rails c development 3> set up the table and appropriate indexes (email + user_id) on the users table in rethinkdb 4> rails c development
5> paste into console..
user1 = User.create(
address_city: "San Francisco" ,
email: "test@nobrainer.io",
password: "strongpass",
address_line1: "8900 7th street" ,
address_line2: "2457" ,
address_phone: "637535346" ,
address_state: "CA" ,
address_zipcode: "94103" ,
name: "usersname" ,
user_id: "d3b67d6f-de23-40c2-8939-0350a5ac0438-2"
)
user1.update(address_zipcode: "99998")
user2 = User.where(address_zipcode: "99998").first
user2
observe nil
returned..
expected result (something like):
#<User address_city: "San Francisco", address_line1: "8900 7th street", address_line2: "2457", address_phone: "637535346", address_state: "CA", address_zipcode: "99998", name: "usersname", user_id: "d3b67d6f-de23-40c2-8939-0350a5ac0438-2", id: "4R0wJAlx0TWvPR", email: "test@nobrainer.io">
problem: The user1.update(address_zipcode: "99998")
command does not persist into rethinkdb
I don't see the user.rb file. Please provide a git repo with the code, and the instructions to run the test.
sorry jumped the gun .. attached in above comment
the issue actually belongs in devise-nobrainer
or devise
or worst case rails
I believe.. but I assumed it was a nobrainer
issue initially .. and now (after writing the standalone script) i think it is not.
Validations failed:
you muse use update!()
, not update()
otherwise you won't see the exception:
2.3.3 :027 > user1.update!(address_zipcode: "99998")
[ 1.9ms] r.table("nobrainer_locks").get( "oot+R2Hmm2rQrodc13KcBVWENek=").replace {|var_10| r.branch( var_10.eq(nil).or(var_10[:expires_at].lt(r.now)), {"key" => "uniq:devise_nobrainer_issue_development:users:email:test@nobrainer.io", "key_hash" => "oot+R2Hmm2rQrodc13KcBVWENek=", "instance_token" => "4R1Av5jfi81NY9", "expires_at" => r.now.add(60)}, var_10 )}
[ 1.4ms] r.table("users").get_all("test@nobrainer.io", {"index" => :email}).count
[ 1.1ms] r.table("users").get_all("test@nobrainer.io", {"index" => :email}).count
[ 1.2ms] r.table("nobrainer_locks").get( "oot+R2Hmm2rQrodc13KcBVWENek=").replace {|var_11| r.branch( var_11[:instance_token].default(nil).eq("4R1Av5jfi81NY9"), nil, var_11 )}
NoBrainer::Error::DocumentInvalid: NoBrainer::Error::DocumentInvalid
from /home/pafy/.rvm/gems/ruby-2.3.3/gems/nobrainer-0.33.0/lib/no_brainer/document/persistance.rb:108:in `update!'
from (irb):27
from /home/pafy/.rvm/gems/ruby-2.3.3/gems/railties-5.0.1/lib/rails/commands/console.rb:65:in `start'
from /home/pafy/.rvm/gems/ruby-2.3.3/gems/railties-5.0.1/lib/rails/commands/console_helper.rb:9:in `start'
from /home/pafy/.rvm/gems/ruby-2.3.3/gems/railties-5.0.1/lib/rails/commands/commands_tasks.rb:78:in `console'
from /home/pafy/.rvm/gems/ruby-2.3.3/gems/railties-5.0.1/lib/rails/commands/commands_tasks.rb:49:in `run_command!'
from /home/pafy/.rvm/gems/ruby-2.3.3/gems/railties-5.0.1/lib/rails/commands.rb:18:in `<top (required)>'
from /home/pafy/.rvm/gems/ruby-2.3.3/gems/activesupport-5.0.1/lib/active_support/dependencies.rb:293:in `require'
from /home/pafy/.rvm/gems/ruby-2.3.3/gems/activesupport-5.0.1/lib/active_support/dependencies.rb:293:in `block in require'
from /home/pafy/.rvm/gems/ruby-2.3.3/gems/activesupport-5.0.1/lib/active_support/dependencies.rb:259:in `load_dependency'
from /home/pafy/.rvm/gems/ruby-2.3.3/gems/activesupport-5.0.1/lib/active_support/dependencies.rb:293:in `require'
from /home/pafy/tmp/xxx/devise-nobrainer-issue/bin/rails:9:in `<top (required)>'
from /home/pafy/.rvm/gems/ruby-2.3.3/gems/activesupport-5.0.1/lib/active_support/dependencies.rb:287:in `load'
from /home/pafy/.rvm/gems/ruby-2.3.3/gems/activesupport-5.0.1/lib/active_support/dependencies.rb:287:in `block in load'
from /home/pafy/.rvm/gems/ruby-2.3.3/gems/activesupport-5.0.1/lib/active_support/dependencies.rb:259:in `load_dependency'
from /home/pafy/.rvm/gems/ruby-2.3.3/gems/activesupport-5.0.1/lib/active_support/dependencies.rb:287:in `load'
from /home/pafy/.rvm/gems/ruby-2.3.3/gems/nobrainer-0.33.0/lib/no_brainer/fork.rb:9:in `fork'
from /home/pafy/.rvm/gems/ruby-2.3.3/gems/nobrainer-0.33.0/lib/no_brainer/fork.rb:9:in `fork'
from /home/pafy/.rvm/rubies/ruby-2.3.3/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /home/pafy/.rvm/rubies/ruby-2.3.3/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from -e:1:in `<main>'
2.3.3 :031 > user1.errors
=> #<ActiveModel::Errors:0x00000004a104d8 @base=#<User address_city: "San Francisco", email: "test@nobrainer.io", address_line1: "8900 7th street", address_line2: "2457", address_phone: "637535346", address_state: "CA", address_zipcode: "99998", name: "usersname", user_id: "d3b67d6f-de23-40c2-8939-0350a5ac0438-2", id: "4R190jg40dg3sP">, @messages={:email=>["is already taken", "is already taken"]}, @details={:email=>[{:error=>:taken, :value=>"test@nobrainer.io"}, {:error=>:taken, :value=>"test@nobrainer.io"}]}>
I'll look into it
nevermind, I was trying to create the user twice. disregard my previous message. Here's what I have and it's working well (aside from the missing devise template):
thanks so much for checking on your end.. I will try to point this at a compose.io cloud based rethinkdb instance and check again..
I say this because I had been running my app normally with nobrainer before and have had no issues with the cloud based rethinkdb instance.. this is the first time I tried to develop with a local rethinkdb instance though..
It might be my local rethinkdb setup with brew or some port mapping issue on mac.
this is super strange.. everything works fine using compose's rethinkdb in the cloud.. but not using my local rethinkdb on macOS :(
@nviennot just out of curiosity.. what connection string to rethinkdb were you using?
The default localhost
thanks.. I think there is an issue with my rethinkdb installation then
Trying to fetch a user like so:
u = User.where(confirmation_token: "589y9cD9rGx_sackYuH_").first
and then update some fields:
u.update(address_zipcode: "99999")
After updating I get a red colored..
[ 22.9ms] r.table("users").get("4QoCjf1D5Mg5Il").update {|var_3| {"address_zipcode" => "99999", "updated_at" => r.expr(2017-02-13 08:37:41 +0000)}}
=> true
but the web ui for rethinkdb does not show any changes..
I'm running Fantasia locally on macOS (installed via homebrew)
I discovered the issue when using devise-nobrainer.. The user.create seems to work fine but there seems be an issue with .update