-
-
Notifications
You must be signed in to change notification settings - Fork 197
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
Make Dynamoid Rails 5 compatible and help avoid errors when no tables exist yet #63
Conversation
allow this gem to run on rails 5
adding the active_model_serializers runtime dependency
In an effort to eliminate the XML errors I was seeing while running this in rails 5, I added active-model-serializers-xml as a runtime dependency. It changed nothing, I was still getting those errors.
This was throwing errors stating that ActiveModel::Serializers::XML couldn't be found. After removing it, everything seemed to work fine for me. What is it being used for?
Can you add a test that would highlight the original problem please? |
sure. If I get some time. It may be a little while. |
@@ -19,7 +19,7 @@ def tables | |||
if !@tables_.value | |||
@tables_.swap{|value, args| benchmark('Cache Tables') {list_tables}} | |||
end | |||
@tables_.value | |||
@tables_.value || [] |
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.
Hey everyone! I'm also looking to use Dynamoid with Rails 5 and so I fork it and apply all this changes and started to build a test to cover this situation (FYI I did not experience this issue though). But looking into the code I got confuse with this change, because the
if !@tables_.value
@tables_.swap{|value, args| benchmark('Cache Tables') {list_tables}}
end
should do exactly the same as this @tables_.value || []
because the output of the method list_tables
of the Dynamoid::AdapterPlugin::AwsSdkV2
is an empty array. So I imagine that's this is depending at the end on the Aws::DynamoDB::Client
version that you are using, because the Dynamoid::AdapterPlugin::AwsSdkV2
send that call to the client
that it's a Aws::DynamoDB::Client
.
Bottom line the response of the Aws::DynamoDB::Client.list_tables
is a Aws::DynamoDB::Types::ListTablesOutput
struct with a table_names
array.
I'm using aws-sdk-core (2.2.33)
and aws-sdk-resources (2.2.33)
.
Any other thought?
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.
Very interesting report. In my case, .value was nil and it was causing later lines of code doing a tables.include? to fail if I had no tables initially. Is there a reason why it would be bad to default to an empty array here? There's almost no performance cost and obviously there are edge cases where .value is nil. I leave it up to the community to decide. I'll keep using my fork if you want to get rid of that change since this works great for me.
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.
Hey @adamthedeveloper what is the error that is returning without that @tables_.value || []
? could be this one: Aws::DynamoDB::Errors::ResourceNotFoundException: Cannot do operations on a non-existent table
?
If that's the case has to be with the caching that Dynamoid is doing of the tables names.
What's your version of aws-sdk-core
and aws-sdk-resources
in order if we can maybe narrow the issue and I'm happy to built a test case for it if we found the scenario
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.
Do you have any insight @adamthedeveloper? just trying to find the scenario to properly wrap a test case for it.
Thanks!
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.
sorry about being so slow to get back. I'll take a look tonight by bootstrapping a new project with the same dependencies and report back with the errors I saw originally. The error posted by @cavi21 doesn't look like the error I originally saw. The exception thrown was when .include? was being called on the tables method. I'd get .include? can't be called on nil.
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.
Awesome and no worries! let me know If I can be useful for anything!
This PR is a little old and quite necessary. Don't you need some help to finish it? |
Thanks for the bump. I'll take a look tonight and report what my environment has in it. I'll write some tests too. |
Also feel free te let me know if I can help on anything here @adamthedeveloper! thanks for the time |
Wasn't able to get to it last night. Will try again tonight. |
Here's the list of my Gems: *** LOCAL GEMS *** actioncable (5.0.0.beta2) Running a server fails instantly with: /usr/local/rvm/gems/ruby-2.3.0@dynamotest2/gems/bundler-1.12.5/lib/bundler/runtime.rb:89:in Bundler Error Backtrace: from /usr/local/rvm/gems/ruby-2.3.0@dynamotest2/gems/bundler-1.12.5/lib/bundler/runtime.rb:85:in block (2 levels) in require' from /usr/local/rvm/gems/ruby-2.3.0@dynamotest2/gems/bundler-1.12.5/lib/bundler/runtime.rb:81:in each'from /usr/local/rvm/gems/ruby-2.3.0@dynamotest2/gems/bundler-1.12.5/lib/bundler/runtime.rb:81:in block in require' from /usr/local/rvm/gems/ruby-2.3.0@dynamotest2/gems/bundler-1.12.5/lib/bundler/runtime.rb:70:in each'from /usr/local/rvm/gems/ruby-2.3.0@dynamotest2/gems/bundler-1.12.5/lib/bundler/runtime.rb:70:in require' from /usr/local/rvm/gems/ruby-2.3.0@dynamotest2/gems/bundler-1.12.5/lib/bundler.rb:102:in require'from /Users/adammedeiros/Projects/rails/dynamotest/config/application.rb:17:in <top (required)>' from /usr/local/rvm/gems/ruby-2.3.0@dynamotest2/gems/railties-5.0.0.beta2/lib/rails/commands/commands_tasks.rb:88:in require'from /usr/local/rvm/gems/ruby-2.3.0@dynamotest2/gems/railties-5.0.0.beta2/lib/rails/commands/commands_tasks.rb:88:in block in server' from /usr/local/rvm/gems/ruby-2.3.0@dynamotest2/gems/railties-5.0.0.beta2/lib/rails/commands/commands_tasks.rb:85:in tap'from /usr/local/rvm/gems/ruby-2.3.0@dynamotest2/gems/railties-5.0.0.beta2/lib/rails/commands/commands_tasks.rb:85:in server' from /usr/local/rvm/gems/ruby-2.3.0@dynamotest2/gems/railties-5.0.0.beta2/lib/rails/commands/commands_tasks.rb:49:in run_command!'from /usr/local/rvm/gems/ruby-2.3.0@dynamotest2/gems/railties-5.0.0.beta2/lib/rails/command.rb:20:in run' from /usr/local/rvm/gems/ruby-2.3.0@dynamotest2/gems/railties-5.0.0.beta2/lib/rails/commands.rb:19:in <top (required)>'from /Users/adammedeiros/Projects/rails/dynamotest/bin/rails:9:in require' from /Users/adammedeiros/Projects/rails/dynamotest/bin/rails:9:in <top (required)>'from /usr/local/rvm/gems/ruby-2.3.0@dynamotest2/gems/spring-1.6.3/lib/spring/client/rails.rb:28:in load' from /usr/local/rvm/gems/ruby-2.3.0@dynamotest2/gems/spring-1.6.3/lib/spring/client/rails.rb:28:in call'from /usr/local/rvm/gems/ruby-2.3.0@dynamotest2/gems/spring-1.6.3/lib/spring/client/command.rb:7:in call' from /usr/local/rvm/gems/ruby-2.3.0@dynamotest2/gems/spring-1.6.3/lib/spring/client.rb:28:in run'from /usr/local/rvm/gems/ruby-2.3.0@dynamotest2/gems/spring-1.6.3/bin/spring:49:in <top (required)>' from /usr/local/rvm/gems/ruby-2.3.0@dynamotest2/gems/spring-1.6.3/lib/spring/binstub.rb:11:in load'from /usr/local/rvm/gems/ruby-2.3.0@dynamotest2/gems/spring-1.6.3/lib/spring/binstub.rb:11:in <top (required)>' from /Users/adammedeiros/Projects/rails/dynamotest/bin/spring:13:in require'from /Users/adammedeiros/Projects/rails/dynamotest/bin/spring:13:in <top (required)>' from bin/rails:3:in load'from bin/rails:3:in `' Changing the Gemfile to use `Bundler could not find compatible versions for gem "activemodel":
|
@adamthedeveloper active model serializers xml is no long a part of Rails 5. You will need to include it as a dependency... Relates to #69 |
I submit that it's not needed at all. Where in the code is it used? Can we On Wed, Jul 13, 2016 at 3:49 PM, Zero Cool notifications@github.com wrote:
A.R. Medeiros |
I think you will need to bump up the version of active model to do that, but I am not certain. I am not really sure if it is used. Also Rails 5 is now out, so you can rely on a version newer then Beta2 IMO. |
I have a unique environment edge case that required me to make some code Thanks On Wed, Jul 13, 2016 at 3:58 PM, Zero Cool notifications@github.com wrote:
A.R. Medeiros |
I am not sure if it works better, but some time dependencies change between versions so I was just pointing it out. @adamthedeveloper |
Rails 5 support will be added in the next version to be released. Thanks for your work on this @adamthedeveloper & @gwincr11 . Will review soon. |
@adamthedeveloper Please rebase on latest master - Spec suite is fixed!!! |
@@ -23,7 +23,6 @@ module Components | |||
include ActiveModel::Naming | |||
include ActiveModel::Observing if defined?(ActiveModel::Observing) | |||
include ActiveModel::Serializers::JSON | |||
include ActiveModel::Serializers::Xml |
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.
commented similarly on another PR also adding rails 5 support, but don't know which will get fixed up first, so adding here too... beleive this should be include ActiveModel::Serializers::Xml if defined?(ActiveModel::Serializers::Xml)
so people relying on it in old rails versions/adding it back manually via extracted gem can still use it.
Hey @bglusman, I actually question XML's use in past versions. I don't think it's used or On Thu, Sep 15, 2016 at 9:41 AM, Brian Glusman notifications@github.com
A.R. Medeiros |
Resolved by #109 |
The nil object doesn't have an include? method. In case the tables variable is nil, default it to an empty array so the .include? works.
Remove the inclusion of ActiveModel::Serializers::Xml from components.rb. It's throwing errors and from what I can tell, it's not used anywhere in the codebase. Check my search though: https://github.com/Dynamoid/Dynamoid/search?q=XML&type=Code&utf8=%E2%9C%93
After making these tweaks, I was able to successfully run this gem in Rails 5 without any initial tables.