panko_serializer icon indicating copy to clipboard operation
panko_serializer copied to clipboard

Multiple NoMethod error on serializers

Open Kadaaran opened this issue 5 years ago • 6 comments

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 ! 🤚

Kadaaran avatar Jul 08 '19 09:07 Kadaaran

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?

yosiat avatar Jul 10 '19 09:07 yosiat

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 !

Kadaaran avatar Jul 10 '19 16:07 Kadaaran

@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 avatar Jul 11 '19 10:07 yosiat

@Kadaaran any update on reproduction?

yosiat avatar Jul 27 '19 14:07 yosiat

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.

Kadaaran avatar Aug 01 '19 15:08 Kadaaran

Hi @Kadaaran !

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

yosiat avatar Aug 10 '19 12:08 yosiat