Config.namespace still adds namespacing even if set to nil #78

Closed
tvmendoza opened this Issue Jun 8, 2016 · 11 comments

Projects

None yet

6 participants

@tvmendoza

I am setting my configuration to the following:

config.adapter = 'aws_sdk_v2'
config.namespace = nil
config.warn_on_scan = true
config.read_capacity = 5
config.write_capacity = 5

However, when i get the result I am getting the following:

get_item(table_name:"_tableName",key:{"email"=>{s:"a@a.com"}})

In this example my table is called "tableName" however it is still adding the _, I tried setting config.namespace to "" and nil but it did not work.

Is this an error or did I just misunderstood the documentation?

@cignoir
Contributor
cignoir commented Jun 9, 2016 edited

@tvmendoza

It seems to be working fine for me.

require 'dynamoid'
require 'aws-sdk'

Dynamoid.configure do |config|
  config.adapter = 'aws_sdk_v2'
  config.namespace = nil
  config.endpoint = 'http://localhost:8000'
end

class SampleModel
  include Dynamoid::Document
  table name: 'table_name', key: :email
end

p SampleModel.table_name
#=>"table_name"

SampleModel.create_table
p Dynamoid::adapter.list_tables
#=>["table_name"]

p SampleModel.create(email: "a@a.com")
#=>I, [2016-06-09T10:20:54.886461 #2552]  INFO -- : (534.42 ms) PUT ITEM - [["table_name", {:created_at=>1465435254.351541, :updated_at=>1465435254.3520389, :email=>"a@a.com"}, {:unless_exists=>[:email, :email]}]]
#<SampleModel:0x000000045aa7b8 @new_record=false, @attributes={:created_at=>Thu, 09 Jun 2016 10:20:54 +0900, :updated_at=>Thu, 09 Jun 2016 10:20:54 +0900, :email=>"a@a.com"}, @associations={}, @changed_attributes={}, @validation_context=nil, @errors=#<ActiveModel::Errors:0x0000000455ad30 @base=#<SampleModel:0x000000045aa7b8 ...>, @messages={}>, @previously_changed={"email"=>[nil, "a@a.com"]}>

p SampleModel.find("a@a.com")
#=>I, [2016-06-09T10:20:54.931604 #2552]  INFO -- : (30.35 ms) GET ITEM - [["table_name", "a@a.com", {}]]
#<SampleModel:0x000000039b64c0 @new_record=false, @attributes={:created_at=>Thu, 09 Jun 2016 10:20:54 +0900, :updated_at=>Thu, 09 Jun 2016 10:20:54 +0900, :email=>"a@a.com"}, @associations={}, @changed_attributes={}>

And also all specs passed on my local.

$ bundle exec rspec spec

...

Finished in 3 minutes 26.9 seconds (files took 0.66104 seconds to load)
309 examples, 0 failures, 4 pending
@alexperto
Contributor

same problem here!

class Measurement
  include Dynamoid::Document

  table name: 'api_data'
end
2.3.0 :003 > Measurement.table_name
 => "_api_data"

what version are you using @cignoir?

@alexperto
Contributor
alexperto commented Jun 16, 2016 edited

it seems like the code is fine, for some reason the latest version didn't work for me, when I used a forked repo it worked perfectly. Anyways, I created a PR to refactor the table-namespacing stuff

bundle show dynamoid
/Users/alexperto/.rvm/gems/ruby-2.3.0/gems/dynamoid-1.1.0

https://github.com/Dynamoid/Dynamoid/pull/79/files

@cignoir
Contributor
cignoir commented Jun 17, 2016 edited

@alexperto
I used v1.1.0 which is directly cloned via github (not rubygems).

I guess the difference of v1.1.0 between github and rubygems causes this problem. The namespacing problem was fixed on Mar 12, 2016. However, the version on rubygems not updated since December 30, 2015.

https://rubygems.org/gems/dynamoid/versions/1.1.0

@philipmw
Hello, I suggest that it is time to bump and deploy new version ๐Ÿš€

@alexperto
Contributor

thanks for looking at it @cignoir,
I temporary fixed it by doing:

gem "dynamoid", git: "https://github.com/Dynamoid/Dynamoid.git"
@bglusman
Collaborator
bglusman commented Aug 7, 2016

If anyone else needs a gem based distribution, we're working on a new one but I had related issue and created dynamoid-edge gem release of a current master snapshot a few months back that will probably fix your issue @tvmendoza , but hopefully @pboling or I will be able to get a new gem release out on the official gem soon.

@archonic
archonic commented Sep 2, 2016

Master branch indeed fixes it, but I'm hoping the release with that fix is pushed to rubygems before we're ready to release our feature. Don't want to be bundling an unversioned branch in production!

@pboling
Collaborator
pboling commented Sep 4, 2016 edited

@bglusman @archonic I am going to release a minor update from current master, to get this particular fix out, along with the rest of the fixes on master. We have a lot of other work to do that will need to be in further releases as well, but we might as well release where we are at now.

@pboling
Collaborator
pboling commented Sep 4, 2016

1.2.0

  • Expose and fix truncate method on adapter (#52, @pcorpet)
  • Enable saving without updating timestamps (#58, @cignoir)
  • Fix projected attributes by checking for :include (#56, @yoshida_tetsuhiro)
  • Make behavior of association where method closer to AR by cloning instead of modifying (#51, @pcorpet)
  • Add boolean field presence validator (#50, @pcorpet)
  • Add association build method (#49, @pcorpet)
  • Fix association create method (#47, #48, @pcorpet)
  • Support range_between (#42, @ayemos)
  • Fix problems with range query (#42, @ayemos)
  • Don't prefix table names when namespace is nil (#40, @brenden)
  • Added basic secondary index support (#34, @sumocoder)
  • Fix query attribute behavior for booleans (#35, @amirmanji)
  • Ignore unknown fields on model initialize (PR #33, @sumocoder)
@pboling
Collaborator
pboling commented Sep 4, 2016 edited

Been trying to get specs passing, and finally won the battle with rspec-retry gem. Also made a few other improvements. 1.2.0 coming shortly.
#100 Please review and comment!

@pboling
Collaborator
pboling commented Sep 4, 2016

Release 1.2.0. Please check it out!

@pboling pboling closed this Sep 4, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment