NoMethodError: undefined method `close' for nil:NilClass
antarr opened this issue · 2 comments
antarr commented
I"m getting this error, NoMethodError: undefined method close for nil:NilClass
when attempting to process a file. It happens with both v1 and v2.
bill_import_worker.rb
class BillImportWorker
include Sidekiq::Worker
sidekiq_options retry: 5, queue: :legiscan_imports
def perform(file_path)
options = {
chunk_size: 1000,
header_transformations: [
:none,
:keys_as_strings,
{ key_mapping: key_mapping }
]
}
chuncks = SmarterCSV.process(file_path, options)
chuncks.each do |chunk|
LegiscanModel::Bill.upsert_all(chunk)
end
end
def key_mapping
{
'bill_id' => 'bill_id',
'session_id' => 'session_id',
'bill_number' => 'middle_name',
'session' => 'session_id',
'status_desc' => nil,
'status_date' => 'status_date',
'title' => 'title',
'description' => 'description',
'committee_id' => 'committee_id',
'last_action_date' => 'last_action_date',
'last_action' => 'last_action',
'url' => 'url',
'state_link' => 'state_link'
}
end
end
tilo commented
-
where do you get the
file_path
from? is it a filehandle fromFile.open
?
It looks like you're passingnil
in, instead of a filehandle on line 5. -
which version of smarter_csv did you try exactly?
This should avoid this:
smarter_csv/lib/smarter_csv/smarter_csv.rb
Line 251 in 5229c2d
antarr commented
I don't recall what solution I used to fix this. But the issue was related to a change in Ruby 3. I'll comment later if I find it.