panko_serializer
panko_serializer copied to clipboard
Multiple NoMethod error on serializers
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 ! 🤚
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?
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 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 ?
@Kadaaran any update on reproduction?
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.
Hi @Kadaaran !
Thanks for trying to reproduce it! I'll try to reproduce it with sidekiq and rails cache and will update.