Comments (18)
Can you provide an script to reproduce this issue? it will be easier to pip-point the issue.
Probably this is not a CSV problem, specially if it's noted only when you upgrade Rails - so I'd suggest to review with and without Rails in your bundle.
from csv.
Could you also show full backtrace of:
> CSV.generate(headers: true)
ArgumentError: Cannot parse nil as CSV
from /usr/local/bundle/gems/csv-3.2.3/lib/csv.rb:1893:in `initialize'
from csv.
You can use local csv
by using gem "csv", path: "/local/path/to/csv"
in your Gemfile
:
$ git clone https:///github.com/ruby/csv.git /tmp/csv
$ editor Gemfile
(Replace 'gem "csv"' with 'gem "csv", path: "/tmp/csv".)
$ bundle instlal
$ ...
from csv.
Hey @esparta
> CSV.generate(headers: true)
ArgumentError: Cannot parse nil as CSV
from /usr/local/bundle/gems/csv-3.2.3/lib/csv.rb:1893:in `initialize'
I used this code. I used this with my Rails 6 and it is working with all the same gems. This is not working only after I updated my rails and ruby version. Thanks.
from csv.
Sorry if I was not clear, but with script I mean a complete example which the maintainers (and supporters as myself) can just execute and be able to reproduce without having your bundle. A line with the error it's not enough.
Here's something I did, and it's clear ruby 3.1.2 with bundled CSV gem has not the problem executing this minimal script:
require 'csv'
CSV.generate(headers: true) do |csv|
csv << ['id', 'date', 'amount']
csv << 123, '2022/05/09', 12.40]
end
from csv.
Thanks a lot @esparta Did you test this with rails 7.0.2?
from csv.
Thanks a lot @esparta Did you test this with rails 7.0.2?
No, I didn't and that's what I'm gently asking you: create a reproducible script:
https://guides.rubyonrails.org/contributing_to_ruby_on_rails.html#create-an-executable-test-case
from csv.
Hey @esparta Thanks a lot for your suggestion. Honestly, I did not have any idea about these scripts. Here is my script,
# frozen_string_literal: true
require "bundler/inline"
gemfile(true) do
ruby '3.1.2'
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
# Activate the gem you are reporting the issue against.
gem 'rails', "~> 7.0.2", "= 7.0.2.3"
gem "csv"
end
require "active_support"
require "active_support/core_ext/object/blank"
require "minitest/autorun"
require "csv"
class BugTest < Minitest::Test
def test_csv
attributes = %i[id name version]
all = [
{ id: 1, name: 'Ruby', value: '3.1.2' },
{ id: 2, name: 'Rails', value: '7.0.2' },
{ id: 3, name: 'Bootstrap', value: '4' }
]
CSV.generate(headers: true) do |csv|
csv << attributes
all.each do |data|
csv << [
data[:id],
data[:name],
data[:value]
]
end
end
end
end
from csv.
Hey @esparta Thanks a lot for giving your time. I created a new app with specified ruby and rails version and it did work. I highly doubt if any of the gem I installed is causing this. I am still investigating this and dropping the gem file as well here in case any one wants to have a look.
# frozen_string_literal: true
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '3.1.2'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', "~> 7.0.2", "= 7.0.2.3"
# Use Puma as the app server
gem 'puma'
# Use SCSS for stylesheets
gem 'sass-rails'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
gem 'mini_racer', platforms: :ruby
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.2'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.5'
# Use Redis adapter to run Action Cable in production
gem 'redis', '~> 4.0'
# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.1.0' # , require: false
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: %i[mri mingw x64_mingw]
gem 'rb-readline'
end
gem 'pg'
group :development do
# Access an interactive console on exception pages or by calling 'console' anywhere in the code.
gem 'listen'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'bullet'
gem 'spring', '~> 3.0.0'
end
gem 'capybara-webkit', git: 'https://github.com/thoughtbot/capybara-webkit.git'
group :test do
gem 'factory_bot_rails'
gem 'headless', git: 'https://github.com/leonid-shevtsov/headless.git'
gem 'rails-controller-testing'
gem 'rspec-rails'
gem 'stripe-ruby-mock', git: 'https://github.com/stripe-ruby-mock/stripe-ruby-mock.git', require: 'stripe_mock'
gem 'webmock'
gem 'webrick', git: 'https://github.com/ruby/webrick.git'
# Adds support for Capybara system testing and selenium driver
gem 'capybara'
gem 'selenium-webdriver'
# Easy installation and use of chromedriver to run system tests with Chrome
gem 'webdrivers'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby]
# Used for server-side processing of datatables.
gem 'ajax-datatables-rails', '~> 1.2.0'
# Ability to debug code in real time.
gem 'pry'
# Used for mass imports.
gem 'activerecord-import', git: 'https://github.com/zdennis/activerecord-import'
gem 'sidekiq', github: 'mperham/sidekiq'
# Sidekiq used for backgrounding tasks.
group :production do
source 'https://gems.contribsys.com/' do
gem 'sidekiq-pro'
end
end
gem 'sidekiq-scheduler'
# CSV parsing.
gem 'csv'
# user authentication
gem 'devise'
# for document validation
gem 'activestorage-validator'
# Generates a visual diagram to represent model relationships.
gem 'railroady'
# pagination
gem 'will_paginate' # remove
# Convert number to words.
gem 'humanize'
# Slack-ruby-client
gem 'async-websocket', '~> 0.8.0'
gem 'eventmachine'
gem 'slack-ruby-client'
gem 'websocket-driver'
# Message implementation
gem 'twilio-ruby'
# For sidekiq web
gem 'rack'
# For detecting mime types
gem 'mime'
# to call the api from rails application
gem 'rest-client'
gem 'activerecord-session_store'
# To get the next available day after a provided day
gem 'chronic'
# To get current season for password attacks
gem 'ruby-seasons'
# active storage validation
gem 'active_storage_validations'
# necessary for AWS client
gem 'aws-sdk-ec2'
gem 'aws-sdk-s3'
gem 'aws-sdk-ssm'
gem 'aws-sdk-wafv2'
gem 'terminal-table'
gem 'time_difference'
# For PDF generation
gem 'grover'
# Dumping database
gem 'seed_dump'
# Amazon SQS
gem 'aws-sdk-sqs'
gem 'combine_pdf' # to combine the pdfs for report
# Establish Audit Trail
gem 'audited'#, '~> 4.9'
gem 'stripe'
# Ability to duplicate records
gem 'amoeba'
# Calculating percentage changes
gem 'percentage'
# XML/HTML Parser
gem 'nokogiri'
# Atomic Red Team
gem 'atomic-red-team', git: 'https://www.github.com/redcanaryco/atomic-red-team.git', branch: :master
# Better Rails C Colors
gem 'awesome_print'
gem 'jwt'
# Mailchimp
gem 'MailchimpMarketing'
gem 'cocoon'
# Handle expanding and compacting IP addresses and ranges.
gem 'ipaddr'
gem 'rotp'
gem 'rqrcode'
# Sentry.io
gem 'sentry-rails'
gem 'sentry-ruby'
gem 'sentry-sidekiq'
# rubocop
gem 'rubocop'
gem 'rubocop-rails'
gem 'rubocop-rspec'
# Brakeman static analysis tool
gem 'brakeman'
# Security checks
gem 'bundler-audit'
gem 'zeitwerk'
# Rail 7 upgrade
gem "sprockets-rails"
gem 'cssbundling-rails'
gem 'jsbundling-rails'
gem 'stimulus-rails'
from csv.
Could you also show the output of #245 (comment) ?
(I couldn't reproduce this...)
from csv.
Hey @kou
[1] pry(RootCause)> e.backtrace
=> ["/usr/local/bundle/gems/csv-3.2.3/lib/csv.rb:1893:in `initialize'",
"/usr/local/bundle/gems/csv-3.2.3/lib/csv.rb:1411:in `new'",
"/usr/local/bundle/gems/csv-3.2.3/lib/csv.rb:1411:in `generate'",
"/root/myapp/app/models/root_cause.rb:20:in `to_csv'",
"/usr/local/bundle/gems/activerecord-7.0.2.3/lib/active_record/relation/delegation.rb:108:in `public_send'",
"/usr/local/bundle/gems/activerecord-7.0.2.3/lib/active_record/relation/delegation.rb:108:in `block in method_missing'",
"/usr/local/bundle/gems/activerecord-7.0.2.3/lib/active_record/relation.rb:880:in `_scoping'",
"/usr/local/bundle/gems/activerecord-7.0.2.3/lib/active_record/relation.rb:428:in `scoping'",
"/usr/local/bundle/gems/activerecord-7.0.2.3/lib/active_record/relation/delegation.rb:108:in `method_missing'",
"/root/myapp/app/controllers/consultants/root_causes_controller.rb:64:in `block (2 levels) in export_root_causes'",
"/usr/local/bundle/gems/actionpack-7.0.2.3/lib/action_controller/metal/mime_responds.rb:214:in `respond_to'",
"/root/myapp/app/controllers/consultants/root_causes_controller.rb:62:in `export_root_causes'",
"/usr/local/bundle/gems/actionpack-7.0.2.3/lib/action_controller/metal/basic_implicit_render.rb:6:in `send_action'",
"/usr/local/bundle/gems/actionpack-7.0.2.3/lib/abstract_controller/base.rb:214:in `process_action'",
"/usr/local/bundle/gems/actionpack-7.0.2.3/lib/action_controller/metal/rendering.rb:53:in `process_action'",
"/usr/local/bundle/gems/actionpack-7.0.2.3/lib/abstract_controller/callbacks.rb:234:in `block in process_action'",
"/usr/local/bundle/gems/activesupport-7.0.2.3/lib/active_support/callbacks.rb:118:in `block in run_callbacks'",
"/usr/local/bundle/gems/audited-5.0.2/lib/audited/sweeper.rb:16:in `around'",
"/usr/local/bundle/gems/activesupport-7.0.2.3/lib/active_support/callbacks.rb:127:in `block in run_callbacks'",
"/usr/local/bundle/gems/audited-5.0.2/lib/audited/sweeper.rb:16:in `around'",
"/usr/local/bundle/gems/activesupport-7.0.2.3/lib/active_support/callbacks.rb:127:in `block in run_callbacks'",
"/usr/local/bundle/gems/actiontext-7.0.2.3/lib/action_text/rendering.rb:20:in `with_renderer'",
"/usr/local/bundle/gems/actiontext-7.0.2.3/lib/action_text/engine.rb:69:in `block (4 levels) in <class:Engine>'",
"/usr/local/bundle/gems/activesupport-7.0.2.3/lib/active_support/callbacks.rb:127:in `instance_exec'",
"/usr/local/bundle/gems/activesupport-7.0.2.3/lib/active_support/callbacks.rb:127:in `block in run_callbacks'",
"/usr/local/bundle/gems/activesupport-7.0.2.3/lib/active_support/callbacks.rb:138:in `run_callbacks'",
"/usr/local/bundle/gems/actionpack-7.0.2.3/lib/abstract_controller/callbacks.rb:233:in `process_action'",
"/usr/local/bundle/gems/actionpack-7.0.2.3/lib/action_controller/metal/rescue.rb:22:in `process_action'",
"/usr/local/bundle/gems/actionpack-7.0.2.3/lib/action_controller/metal/instrumentation.rb:67:in `block in process_action'",
"/usr/local/bundle/gems/activesupport-7.0.2.3/lib/active_support/notifications.rb:206:in `block in instrument'",
"/usr/local/bundle/gems/activesupport-7.0.2.3/lib/active_support/notifications/instrumenter.rb:24:in `instrument'",
"/usr/local/bundle/gems/activesupport-7.0.2.3/lib/active_support/notifications.rb:206:in `instrument'",
"/usr/local/bundle/gems/actionpack-7.0.2.3/lib/action_controller/metal/instrumentation.rb:66:in `process_action'",
"/usr/local/bundle/gems/actionpack-7.0.2.3/lib/action_controller/metal/params_wrapper.rb:259:in `process_action'",
"/usr/local/bundle/gems/activerecord-7.0.2.3/lib/active_record/railties/controller_runtime.rb:27:in `process_action'",
"/usr/local/bundle/gems/actionpack-7.0.2.3/lib/abstract_controller/base.rb:151:in `process'",
"/usr/local/bundle/gems/actionview-7.0.2.3/lib/action_view/rendering.rb:39:in `process'",
"/usr/local/bundle/gems/actionpack-7.0.2.3/lib/action_controller/metal.rb:188:in `dispatch'",
"/usr/local/bundle/gems/actionpack-7.0.2.3/lib/action_controller/metal.rb:251:in `dispatch'",
"/usr/local/bundle/gems/actionpack-7.0.2.3/lib/action_dispatch/routing/route_set.rb:49:in `dispatch'",
"/usr/local/bundle/gems/actionpack-7.0.2.3/lib/action_dispatch/routing/route_set.rb:32:in `serve'",
"/usr/local/bundle/gems/actionpack-7.0.2.3/lib/action_dispatch/journey/router.rb:50:in `block in serve'",
:
from csv.
Could you also show this line "/root/myapp/app/models/root_cause.rb:20:in `to_csv'" ?
from csv.
CSV.generate(headers: true) do |csv|
This is at line @kou
from csv.
Could you add p str
debug print before "/usr/local/bundle/gems/csv-3.2.3/lib/csv.rb:1411"?
from csv.
Could you also add p str.method(:nil?)
debug print before "/usr/local/bundle/gems/csv-3.2.3/lib/csv.rb:1411"?
from csv.
Hey @kou This is a gem file and I don't have any local file with this name so I won't be able to make any changes you have mentioned.
from csv.
This is what I got @kou
str.nil? -----> true
str.method(:nil?) -------> #<Method: String#nil?() /root/myapp/config/initializers/string.rb:25>
from csv.
Hey @kou Thanks a lot for suggesting this. I found the issue. .nil?
was overwritten in my string.rb file for some reason which caused this. I removed it and now it is working. Thanks a lot all. closing this out.
from csv.
Related Issues (20)
- New bugfix version for the changes on master HOT 1
- `CSV::Row` pattern matching `Symbol` assumption HOT 1
- :date_time converter fails to recognize "YYYY-MM-DD HH:MM" HOT 7
- Add quoted information to CSV::FieldInfo HOT 1
- ArgumentError: unknown encoding name - iso-8859-1|utf-8 HOT 2
- Feature Request: Generate CSV String from Array HOT 5
- #eof? method returning wrong value when it's used on a csv file HOT 3
- #eof? method returning wrong value when it's used on a csv file with #each, #map, #filter HOT 1
- row access method(like .first, .count, .map) remove row unintentionally HOT 2
- New release for Ruby 3.2 HOT 7
- How about GH releases generated by `gh release create --generate-notes` HOT 5
- feature: add option to limit length of strings HOT 3
- Suggestion to add `sep` option HOT 1
- Broken links in documention HOT 11
- Duplicated last line in CSV.foreach HOT 14
- Recipes not copied downstream HOT 6
- A fiber to execute ':heder_converters' has been changed since v3.2.6 HOT 1
- liberal parsing does not split column as expected with quote at end of column HOT 8
- Inconsistent behaviour between `CSV::Table.new` and `CSV.parse` HOT 10
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from csv.