Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple NoMethod error on serializers #46

Open
Kadaaran opened this issue Jul 8, 2019 · 6 comments
Open

Multiple NoMethod error on serializers #46

Kadaaran opened this issue Jul 8, 2019 · 6 comments

Comments

@Kadaaran
Copy link

Kadaaran commented Jul 8, 2019

Hi there 馃憢
First of all I've been using Panko for a while and it's really great !

What happened ?

I've been encounting some weird errors recently. It seems Panko can't find my main object and its attributes. Even if the main object exists and is valid.

Context

This is my serializer method 馃憞

def template_colour
    object.template.colour.hex_code
 end

I get from time to time NoMethodError: undefined method template' for nil:NilClass` which is weird because if I reload or do something it disappears. It's not triggering every time.

Plus, when I go into my console I can find my template, the colour association and the hex_code without any problem.
It feels like Panko can't get the main object fast enough to render it.

Did you have any king of errors like mine and do you have any idea how to fix it ?

Thanks ! 馃

@yosiat
Copy link
Owner

yosiat commented Jul 10, 2019

Hi @Kadaaran !

Thanks for the bug report, I never encountered this error in my production environment.

Which version of panko are you using? are you running on a threaded environment (puma? sidekiq?)?
Can you add the calling method to the serializer?

@Kadaaran
Copy link
Author

Hi @yosiat !

I tried in development and it happens in dev as well 馃
Panko: gem 'panko_serializer', '~> 0.5.1'
Sidekiq: gem 'sidekiq', '~> 4.2.10'

The method:

cache_key = "sessions-index-#{(@template || @group).cache_key}-#{@sessions.cache_key}"
sessions_json = Rails.cache.fetch(cache_key, expires_in: 2.days) do
   Panko::ArraySerializer.new(@sessions.order(start_time: :asc), each_serializer: SessionSerializer).to_json
end

Thanks !

@yosiat
Copy link
Owner

yosiat commented Jul 11, 2019

@Kadaaran I can't reproduce this locally.

Can you please try and upgrade to latest panko version and see if it fixes the issue for you?
Can you somehow create a script that reproduces the issue with https://github.com/rails/rails/blob/master/guides/bug_report_templates/active_record_gem.rb ?

@yosiat
Copy link
Owner

yosiat commented Jul 27, 2019

@Kadaaran any update on reproduction?

@Kadaaran
Copy link
Author

Kadaaran commented Aug 1, 2019

Hey @yosiat !
Sorry for getting back to you this late, I just updated my code and I think it has something to do with the cache and Panko together so I removed the cache for now and I'll try to dig further into it when I'll have more time, it's getting busy there sorry about it.

@yosiat
Copy link
Owner

yosiat commented Aug 10, 2019

Hi @Kadaaran !

Thanks for trying to reproduce it!
I'll try to reproduce it with sidekiq and rails cache and will update.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants