-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
no implicit conversion of nil into String #1176
Comments
hi, @Padchi, I'm having issues replicated our error with the given information. A few questions:
|
Is the id actually nil? Might be related to 995bbcc btw, Post.all might not be a good idea, unless you mean that just as example code |
Hello @NullVoxPopuli and @bf4!
All my serializers have the same problem.
class Post < ActiveRecord::Base
nilify_blanks
belongs_to :user
has_many :comments, as: :commentable, dependent: :destroy
has_many :attachments, as: :attachable, dependent: :destroy
extend FriendlyId
friendly_id :title, use: :slugged
validates :content, :title, :published_on, presence: true
before_save :downcase_tags
private
def downcase_tags
self.tags.map!(&:downcase) unless self.tags.blank?
end
end
create_table "posts", id: :uuid, default: "uuid_generate_v4()", force: :cascade do |t|
t.string "title", limit: 255
t.text "content"
t.string "image", limit: 255
t.datetime "created_at"
t.datetime "updated_at"
t.uuid "user_id"
t.string "slug", limit: 255
t.date "published_on"
t.string "tags", limit: 255, default: [], array: true
end
add_index "posts", ["slug"], name: "index_posts_on_slug", using: :btree
add_index "posts", ["tags"], name: "index_posts_on_tags", using: :gin
No i tried with a simple show action as well.
No posts in my database has a null id.
That's just my simplified example, but i got the same error with my real code |
B mobile phone
Ok, but if you def id
fail object.id.inspect
end in your |
@bf4 Exactly the same thing unfortunately |
That tells me that your |
@bf4 I don't get it. If my posts table is empty i just get a response with |
@bf4 and @NullVoxPopuli i have replicated the error, you can find it here https://github.com/Padchi/ams-test/tree/master |
Will look into it in an hour. |
Hi @Padchi I cant reproduce the error using your test repo. I did:
The GET
The GET {"data":[{"id":"1","type":"post"},{"id":"2","type":"post"},{"id":"3","type":"post"},{"id":"4","type":"post"},{"id":"5","type":"post"}]} |
@dukex how is that even possible? I used a fresh clean gemset and i guess that you use the same ruby version as specified in the gemfile? |
the same problem on 0.10.0 rc3 |
@chenghung it's only on rc3 for me, not on rc2 |
@dukex I tested the repo on ruby 2.2.3 to and it's the same problem so don't think that's ruby is the problem. But still thinks it's wierd that you don't get the error with the same repo as me. |
I got the Post but no problems with
|
I don't think it's something wrong with the id, i get the error on this simple thing: def index
serializer = Class.new(ActiveModel::Serializer)
end Know that it's bad code and that it doesn't do anything but just wanted to show that the error throws by just accessing And after that code i finally get something from Framework Trace:
believe it is 215fb85 that creates the problem |
@Padchi What's your platform? (OS version, ruby version, etc.) |
@beauby OS X 10.10.5, RVM 1.26.11, ruby 2.2.1 (also tried 2.2.3). You need something more? |
I'm seeing the same in RC3. A simple (contrived) example: Example serializer
RC2
RC3
|
@bernsno You should not call SerializableResource.new({date: 1, score: 1, description: 1, count: 1}, serializer: ScoreSerializer) |
I managed to replicate the error consistently using edge Rails (5.0.0.alpha fef1064) git clone git://github.com/rails/rails.git
cd rails && bundle
bundle exec railties/exe/rails new ../myproject --edge --api
cd ../myproject
bundle exec bin/rails g scaffold user email:string
rake db:migrate Inside the Rails console create a user User.create(email: "[email protected]") Launch the Rails server (bundle exec bin/rails s) and produce the error by doing a basic GET request curl http://locahost:3000/users.json I don't know if this will help at all but I also discovered that this error only appears in 0.10.0.rc3' but not in '0.10.0.rc2'. So by forcing the version of the gem to 0.10.0.rc2 the error goes away. gem 'active_model_serializers', '0.10.0.rc2' |
This is expected behavior. Serializer is just a bad name for historical reasons. See https://github.com/rails-api/active_model_serializers#using-a-serializer-without-render |
@codehugger I think you might be having a different issue |
@bf4 so how would you make my trivial example work using rc3? |
Although you should really provide an object rather than a hash. |
I get that #1176 is the way to do a serialization outside the context of a controller's render call but I am only using the controller's render call when requesting http://localhost:3000/users.json class UsersController < ApplicationController
...
def index
@users = User.all
render json: @users
end
...
end I am doing no customization what so ever and the generated serializer inside app/serializers looks like this class UserSerializer < ActiveModel::Serializer
attributes :id, :email
end |
With
|
using rake db:seed didn't change anything for me. :-\ |
I wonder if this is something wrong with the environment? |
Maybe this isn't supposed to work but:
|
why are you doing that? |
Just tried to replicate:
My post 14 days ago, but the same code dosn't give the same error anymore. |
@Padchi what happens if you try master of ams in your gemfile? |
@NullVoxPopuli just tried, exactly the same thing. |
@Padchi, @joaomdmoura is going to take a look at this later. I'm personally of the opinion that the cache_key maybe shouldn't be generated the way it is, because there is no caller_file. This only happens in May I ask, how are you running / starting your server? |
@NullVoxPopuli With a simple rails s in terminal. Tried with pow but same thing there. |
are you using |
Nope zsh, oh my zsh |
I'll install and try zsh, one sec |
zsh (aside from not interpreting my PS1 correctly) behaves the same as bash in this scenario. :-\ |
I don't get it, i'm not doing anything fancy except ZSH and RVM... Whole Framework Trace:
|
my next step would maybe see if you can replicate it on a linux vm? using virtualbox or something? |
We need to write up this debug stuff in contributing or troubleshooting |
👍 @bf4 |
output warning Closes rails-api#1176
I've the same error only in production environment with active_model_serializers 0.10.0.rc3, instead with rc2 version all works well. My
produciton.rb (default settings)Rails.application.configure do
config.cache_classes = true
config.eager_load = true
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present?
config.log_level = :debug
config.i18n.fallbacks = true
config.active_support.deprecation = :notify
config.log_formatter = ::Logger::Formatter.new
config.active_record.dump_schema_after_migration = false
end test_serializer.rbclass TestSerializer < ActiveModel::Serializer
attributes :id, :name
end test migrationclass CreateTests < ActiveRecord::Migration
def change
create_table :tests do |t|
t.string :name
t.timestamps
end
end
end when i start WEBrick or console or I try to seed the database in Production environment I've got this error: ams_rc3_bug bin/rails c -e production
/Users/Nico/.rvm/gems/ruby-2.2-head/gems/active_model_serializers-0.10.0.rc3/lib/active_model/serializer.rb:152:in `read': no implicit conversion of nil into String (TypeError)
from /Users/Nico/.rvm/gems/ruby-2.2-head/gems/active_model_serializers-0.10.0.rc3/lib/active_model/serializer.rb:152:in `digest_caller_file'
from /Users/Nico/.rvm/gems/ruby-2.2-head/gems/active_model_serializers-0.10.0.rc3/lib/active_model/serializer.rb:47:in `inherited'
from /Users/Nico/Documents/Ruby on Rails/ams_rc3_bug/app/serializers/test_serializer.rb:1:in `<top (required)>'
from /Users/Nico/.rvm/gems/ruby-2.2-head/bundler/gems/rails-0450642c27af/activesupport/lib/active_support/dependencies.rb:492:in `load'
from /Users/Nico/.rvm/gems/ruby-2.2-head/bundler/gems/rails-0450642c27af/activesupport/lib/active_support/dependencies.rb:492:in `block in load_file'
from /Users/Nico/.rvm/gems/ruby-2.2-head/bundler/gems/rails-0450642c27af/activesupport/lib/active_support/dependencies.rb:682:in `new_constants_in'
from /Users/Nico/.rvm/gems/ruby-2.2-head/bundler/gems/rails-0450642c27af/activesupport/lib/active_support/dependencies.rb:491:in `load_file'
from /Users/Nico/.rvm/gems/ruby-2.2-head/bundler/gems/rails-0450642c27af/activesupport/lib/active_support/dependencies.rb:388:in `block in require_or_load'
from /Users/Nico/.rvm/gems/ruby-2.2-head/bundler/gems/rails-0450642c27af/activesupport/lib/active_support/dependencies.rb:37:in `block in load_interlock'
from /Users/Nico/.rvm/gems/ruby-2.2-head/bundler/gems/rails-0450642c27af/activesupport/lib/active_support/dependencies/interlock.rb:12:in `block in loading'
from /Users/Nico/.rvm/gems/ruby-2.2-head/bundler/gems/rails-0450642c27af/activesupport/lib/active_support/concurrency/share_lock.rb:115:in `exclusive'
from /Users/Nico/.rvm/gems/ruby-2.2-head/bundler/gems/rails-0450642c27af/activesupport/lib/active_support/dependencies/interlock.rb:11:in `loading'
from /Users/Nico/.rvm/gems/ruby-2.2-head/bundler/gems/rails-0450642c27af/activesupport/lib/active_support/dependencies.rb:37:in `load_interlock'
from /Users/Nico/.rvm/gems/ruby-2.2-head/bundler/gems/rails-0450642c27af/activesupport/lib/active_support/dependencies.rb:369:in `require_or_load'
from /Users/Nico/.rvm/gems/ruby-2.2-head/bundler/gems/rails-0450642c27af/activesupport/lib/active_support/dependencies.rb:345:in `depend_on'
from /Users/Nico/.rvm/gems/ruby-2.2-head/bundler/gems/rails-0450642c27af/activesupport/lib/active_support/dependencies.rb:261:in `require_dependency'
from /Users/Nico/.rvm/gems/ruby-2.2-head/bundler/gems/rails-0450642c27af/railties/lib/rails/engine.rb:476:in `block (2 levels) in eager_load!'
from /Users/Nico/.rvm/gems/ruby-2.2-head/bundler/gems/rails-0450642c27af/railties/lib/rails/engine.rb:475:in `each'
from /Users/Nico/.rvm/gems/ruby-2.2-head/bundler/gems/rails-0450642c27af/railties/lib/rails/engine.rb:475:in `block in eager_load!'
from /Users/Nico/.rvm/gems/ruby-2.2-head/bundler/gems/rails-0450642c27af/railties/lib/rails/engine.rb:473:in `each'
from /Users/Nico/.rvm/gems/ruby-2.2-head/bundler/gems/rails-0450642c27af/railties/lib/rails/engine.rb:473:in `eager_load!'
from /Users/Nico/.rvm/gems/ruby-2.2-head/bundler/gems/rails-0450642c27af/railties/lib/rails/engine.rb:354:in `eager_load!'
from /Users/Nico/.rvm/gems/ruby-2.2-head/bundler/gems/rails-0450642c27af/railties/lib/rails/application/finisher.rb:56:in `each'
from /Users/Nico/.rvm/gems/ruby-2.2-head/bundler/gems/rails-0450642c27af/railties/lib/rails/application/finisher.rb:56:in `block in <module:Finisher>'
from /Users/Nico/.rvm/gems/ruby-2.2-head/bundler/gems/rails-0450642c27af/railties/lib/rails/initializable.rb:30:in `instance_exec'
from /Users/Nico/.rvm/gems/ruby-2.2-head/bundler/gems/rails-0450642c27af/railties/lib/rails/initializable.rb:30:in `run'
from /Users/Nico/.rvm/gems/ruby-2.2-head/bundler/gems/rails-0450642c27af/railties/lib/rails/initializable.rb:55:in `block in run_initializers'
from /Users/Nico/.rvm/rubies/ruby-2.2-head/lib/ruby/2.2.0/tsort.rb:226:in `block in tsort_each'
from /Users/Nico/.rvm/rubies/ruby-2.2-head/lib/ruby/2.2.0/tsort.rb:348:in `block (2 levels) in each_strongly_connected_component'
from /Users/Nico/.rvm/rubies/ruby-2.2-head/lib/ruby/2.2.0/tsort.rb:429:in `each_strongly_connected_component_from'
from /Users/Nico/.rvm/rubies/ruby-2.2-head/lib/ruby/2.2.0/tsort.rb:347:in `block in each_strongly_connected_component'
from /Users/Nico/.rvm/rubies/ruby-2.2-head/lib/ruby/2.2.0/tsort.rb:345:in `each'
from /Users/Nico/.rvm/rubies/ruby-2.2-head/lib/ruby/2.2.0/tsort.rb:345:in `call'
from /Users/Nico/.rvm/rubies/ruby-2.2-head/lib/ruby/2.2.0/tsort.rb:345:in `each_strongly_connected_component'
from /Users/Nico/.rvm/rubies/ruby-2.2-head/lib/ruby/2.2.0/tsort.rb:224:in `tsort_each'
from /Users/Nico/.rvm/rubies/ruby-2.2-head/lib/ruby/2.2.0/tsort.rb:203:in `tsort_each'
from /Users/Nico/.rvm/gems/ruby-2.2-head/bundler/gems/rails-0450642c27af/railties/lib/rails/initializable.rb:54:in `run_initializers'
from /Users/Nico/.rvm/gems/ruby-2.2-head/bundler/gems/rails-0450642c27af/railties/lib/rails/application.rb:343:in `initialize!'
from /Users/Nico/Documents/Ruby on Rails/ams_rc3_bug/config/environment.rb:5:in `<top (required)>'
from /Users/Nico/.rvm/gems/ruby-2.2-head/gems/spring-1.4.0/lib/spring/application.rb:92:in `require'
from /Users/Nico/.rvm/gems/ruby-2.2-head/gems/spring-1.4.0/lib/spring/application.rb:92:in `preload'
from /Users/Nico/.rvm/gems/ruby-2.2-head/gems/spring-1.4.0/lib/spring/application.rb:143:in `serve'
from /Users/Nico/.rvm/gems/ruby-2.2-head/gems/spring-1.4.0/lib/spring/application.rb:131:in `block in run'
from /Users/Nico/.rvm/gems/ruby-2.2-head/gems/spring-1.4.0/lib/spring/application.rb:125:in `loop'
from /Users/Nico/.rvm/gems/ruby-2.2-head/gems/spring-1.4.0/lib/spring/application.rb:125:in `run'
from /Users/Nico/.rvm/gems/ruby-2.2-head/gems/spring-1.4.0/lib/spring/application/boot.rb:18:in `<top (required)>'
from /Users/Nico/.rvm/rubies/ruby-2.2-head/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /Users/Nico/.rvm/rubies/ruby-2.2-head/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from -e:1:in `<main>' I hope it will be of help! |
+100 open source points! B mobile phone
|
#1260 solves this, a big thanks! Close now or wait for merge? |
@Padchi Let's wait for merge and close both. |
output warning Closes rails-api#1176
Solved this by removing whitespace in file path. CALLER_FILE regex does not like whitespace. This path does not work This path does |
PR? On Mon, Oct 19, 2015 at 2:45 PM, Luc Charbonneau [email protected]
|
Got this error on rc3 but not on rc2 and I do not do anything fancy here:
Application trace:
I get the same error on every adapter
The text was updated successfully, but these errors were encountered: