Code Monkey home page Code Monkey logo

Comments (17)

Fivell avatar Fivell commented on August 29, 2024

@asalgan , It's hard to make suggestions without backtraces of your errors. Can you show it?

from active_admin_import.

asalgan avatar asalgan commented on August 29, 2024

Yep:

/Users/alan/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/csv.rb:1880:in block (2 levels) in shift' /Users/alan/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/csv.rb:1845:ineach'
/Users/alan/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/csv.rb:1845:in block in shift' /Users/alan/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/csv.rb:1805:inloop'
/Users/alan/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/csv.rb:1805:in shift' /Users/alan/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/csv.rb:1747:ineach'
/Users/alan/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/csv.rb:1761:in to_a' /Users/alan/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/csv.rb:1761:inread'
/Users/alan/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/csv.rb:1307:in parse' active_admin_import (2.1.2) lib/active_admin_import/importer.rb:53:incycle'
active_admin_import (2.1.2) lib/active_admin_import/importer.rb:68:in block (2 levels) in import' active_admin_import (2.1.2) lib/active_admin_import/importer.rb:64:ineach_line'
active_admin_import (2.1.2) lib/active_admin_import/importer.rb:64:in block in import' active_admin_import (2.1.2) lib/active_admin_import/importer.rb:61:inopen'
active_admin_import (2.1.2) lib/active_admin_import/importer.rb:61:in import' active_admin_import (2.1.2) lib/active_admin_import/dsl.rb:60:inblock in active_admin_import'
actionpack (4.2.5) lib/action_controller/metal/implicit_render.rb:4:in send_action' actionpack (4.2.5) lib/abstract_controller/base.rb:198:inprocess_action'
actionpack (4.2.5) lib/action_controller/metal/rendering.rb:10:in process_action' actionpack (4.2.5) lib/abstract_controller/callbacks.rb:20:inblock in process_action'
activesupport (4.2.5) lib/active_support/callbacks.rb:117:in call' activesupport (4.2.5) lib/active_support/callbacks.rb:555:inblock (2 levels) in compile'
activesupport (4.2.5) lib/active_support/callbacks.rb:505:in call' activesupport (4.2.5) lib/active_support/callbacks.rb:92:inrun_callbacks'
activesupport (4.2.5) lib/active_support/callbacks.rb:778:in _run_process_action_callbacks' activesupport (4.2.5) lib/active_support/callbacks.rb:81:inrun_callbacks'
actionpack (4.2.5) lib/abstract_controller/callbacks.rb:19:in process_action' actionpack (4.2.5) lib/action_controller/metal/rescue.rb:29:inprocess_action'
actionpack (4.2.5) lib/action_controller/metal/instrumentation.rb:32:in block in process_action' activesupport (4.2.5) lib/active_support/notifications.rb:164:inblock in instrument'
activesupport (4.2.5) lib/active_support/notifications/instrumenter.rb:20:in instrument' activesupport (4.2.5) lib/active_support/notifications.rb:164:ininstrument'
actionpack (4.2.5) lib/action_controller/metal/instrumentation.rb:30:in process_action' actionpack (4.2.5) lib/action_controller/metal/params_wrapper.rb:250:inprocess_action'
activerecord (4.2.5) lib/active_record/railties/controller_runtime.rb:18:in process_action' actionpack (4.2.5) lib/abstract_controller/base.rb:137:inprocess'
actionview (4.2.5) lib/action_view/rendering.rb:30:in process' actionpack (4.2.5) lib/action_controller/metal.rb:196:indispatch'
actionpack (4.2.5) lib/action_controller/metal/rack_delegation.rb:13:in dispatch' actionpack (4.2.5) lib/action_controller/metal.rb:237:inblock in action'
actionpack (4.2.5) lib/action_dispatch/routing/route_set.rb:76:in dispatch' actionpack (4.2.5) lib/action_dispatch/routing/route_set.rb:45:inserve'
actionpack (4.2.5) lib/action_dispatch/journey/router.rb:43:in block in serve' actionpack (4.2.5) lib/action_dispatch/journey/router.rb:30:ineach'
actionpack (4.2.5) lib/action_dispatch/journey/router.rb:30:in serve' actionpack (4.2.5) lib/action_dispatch/routing/route_set.rb:817:incall'
bullet (5.0.0) lib/bullet/rack.rb:10:in call' warden (1.2.6) lib/warden/manager.rb:35:inblock in call'
warden (1.2.6) lib/warden/manager.rb:34:in catch' warden (1.2.6) lib/warden/manager.rb:34:incall'
rack (1.6.4) lib/rack/etag.rb:24:in call' rack (1.6.4) lib/rack/conditionalget.rb:38:incall'
rack (1.6.4) lib/rack/head.rb:13:in call' actionpack (4.2.5) lib/action_dispatch/middleware/params_parser.rb:27:incall'
actionpack (4.2.5) lib/action_dispatch/middleware/flash.rb:260:in call' rack (1.6.4) lib/rack/session/abstract/id.rb:225:incontext'
rack (1.6.4) lib/rack/session/abstract/id.rb:220:in call' actionpack (4.2.5) lib/action_dispatch/middleware/cookies.rb:560:incall'
activerecord (4.2.5) lib/active_record/query_cache.rb:36:in call' activerecord (4.2.5) lib/active_record/connection_adapters/abstract/connection_pool.rb:653:incall'
activerecord (4.2.5) lib/active_record/migration.rb:377:in call' actionpack (4.2.5) lib/action_dispatch/middleware/callbacks.rb:29:inblock in call'
activesupport (4.2.5) lib/active_support/callbacks.rb:88:in __run_callbacks__' activesupport (4.2.5) lib/active_support/callbacks.rb:778:in_run_call_callbacks'
activesupport (4.2.5) lib/active_support/callbacks.rb:81:in run_callbacks' actionpack (4.2.5) lib/action_dispatch/middleware/callbacks.rb:27:incall'
actionpack (4.2.5) lib/action_dispatch/middleware/reloader.rb:73:in call' actionpack (4.2.5) lib/action_dispatch/middleware/remote_ip.rb:78:incall'
bugsnag (3.0.0) lib/bugsnag/rack.rb:33:in call' actionpack (4.2.5) lib/action_dispatch/middleware/debug_exceptions.rb:17:incall'
web-console (2.3.0) lib/web_console/middleware.rb:28:in block in call' web-console (2.3.0) lib/web_console/middleware.rb:18:incatch'
web-console (2.3.0) lib/web_console/middleware.rb:18:in call' actionpack (4.2.5) lib/action_dispatch/middleware/show_exceptions.rb:30:incall'
railties (4.2.5) lib/rails/rack/logger.rb:38:in call_app' railties (4.2.5) lib/rails/rack/logger.rb:20:inblock in call'
activesupport (4.2.5) lib/active_support/tagged_logging.rb:68:in block in tagged' activesupport (4.2.5) lib/active_support/tagged_logging.rb:26:intagged'
activesupport (4.2.5) lib/active_support/tagged_logging.rb:68:in tagged' railties (4.2.5) lib/rails/rack/logger.rb:20:incall'
quiet_assets (1.1.0) lib/quiet_assets.rb:27:in call_with_quiet_assets' actionpack (4.2.5) lib/action_dispatch/middleware/request_id.rb:21:incall'
rack (1.6.4) lib/rack/methodoverride.rb:22:in call' rack (1.6.4) lib/rack/runtime.rb:18:incall'
rack (1.6.4) lib/rack/lock.rb:17:in call' actionpack (4.2.5) lib/action_dispatch/middleware/static.rb:116:incall'
rack (1.6.4) lib/rack/sendfile.rb:113:in call' railties (4.2.5) lib/rails/engine.rb:518:incall'
railties (4.2.5) lib/rails/application.rb:165:in call' rack (1.6.4) lib/rack/content_length.rb:15:incall'
puma (2.16.0) lib/puma/server.rb:557:in handle_request' puma (2.16.0) lib/puma/server.rb:404:inprocess_client'
puma (2.16.0) lib/puma/server.rb:270:in block in run' puma (2.16.0) lib/puma/thread_pool.rb:106:inblock in spawn_thread'
Request

Parameters:

{"utf8"=>"✓",
"authenticity_token"=>"hpifAMJOmSl6r6QkROR280QkoksnX9ZnH314NdqFgbhJ69rhpcp9dy/z1Y07Mv1TlW7cYoH7ULaEe4Hx4cEhFA==",
"active_admin_import_model"=>{"file"=>#<ActionDispatch::Http::UploadedFile:0x007ffd7b6361b0 @tempfile=#Tempfile:/var/folders/08/w7v954d16rv1lxrpp_6lsw4c0000gn/T/RackMultipart20160615-42678-vecwg9.csv,
@original_filename="products.csv",
@content_type="text/csv",
@headers="Content-Disposition: form-data; name="active_admin_import_model[file]"; filename="products.csv"\r\nContent-Type: text/csv\r\n">},
"commit"=>"Import"}

from active_admin_import.

Fivell avatar Fivell commented on August 29, 2024

@asalgan, according to your backtrace your csv has invalid format, that's why exception is happened in csv parsing library (not in sources of this gem) . Please recheck it is valid

from active_admin_import.

asalgan avatar asalgan commented on August 29, 2024

@Fivell I've tried doing that, the CSV is downloaded directly from the link at the bottom of active_admin, would that format it incorrectly? I've ran it through a CSV linter without any issues and made sure it was encoded in UTF-8. Do you know any tools or something I can use to apply a standard format to the entire document as it's being downloaded or uploaded via this gem?

from active_admin_import.

Fivell avatar Fivell commented on August 29, 2024

@asalgan , from you message l can't understand why it can not work, also there were no issues like yours yet, so it would be great if you can create demo project using github that reproduce the bug so I can clone it and check what's going on.

from active_admin_import.

asalgan avatar asalgan commented on August 29, 2024

@Fivell I actually have a new error now, I downloaded the original active_admin page to JSON, removed instances of '\r\n' which weren't showing up in the CSV and now using this code:

active_admin_import validate: false,
    on_duplicate_key_update: [:description, :retail_price, :wholesale_price, :notes],
    ignore: [:id, :name, :created_at, :updated_at, :image_file_name, :image_content_type, :image_file_size, :image_updated_at, :genders, :ages, :categories, :all_categories, :refundable],
    timestamps: false,
    before_batch_import: ->(importer) {
      puts "====================="
      puts importer.csv_lines.map! { |row| puts row }
      puts "====================="
    },
    template_object: ActiveAdminImport::Model.new(
      force_encoding: "UTF-8",
      csv_headers: ["id", "description", "retail_price", "wholesale_price", "notes", "name", "created_at", "updated_at", "image_file_name", "image_content_type", "image_file_size", "image_updated_at", "genders", "ages", "categories", "all_categories", "refundable"]
    )

get this error:

undefined method `each_with_index' for nil:NilClass

Started POST "/admin/products/do_import" for ::1 at 2016-06-15 16:00:01 -0500
Processing by Admin::ProductsController#do_import as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"v6b3aX2NI2PdJ8COwNCQKfUGMxZyjIG7/iXwcDlgkDhw1bKIGgnHPYh7sSe/BhuJJExNP9QoB2plIwm0AiQwlA==", "active_admin_import_model"=>{"file"=>#<ActionDispatch::Http::UploadedFile:0x007fe1ad187130 @tempfile=#Tempfile:/var/folders/08/w7v954d16rv1lxrpp_6lsw4c0000gn/T/RackMultipart20160615-46337-1tnhjmn.CSV, @original_filename="products.CSV", @content_type="text/csv", @headers="Content-Disposition: form-data; name="active_admin_import_model[file]"; filename="products.CSV"\r\nContent-Type: text/csv\r\n">}, "commit"=>"Import"}

from active_admin_import.

asalgan avatar asalgan commented on August 29, 2024

I also tried:

active_admin_import validate: false,
    on_duplicate_key_update: [:description, :retail_price, :wholesale_price, :notes],
    ignore: [:name, :created_at, :updated_at, :image_file_name, :image_content_type, :image_file_size, :image_update_at, :genders, :ages, :categories, :all_categories, :refundable],
    timestamps: false,
    before_batch_import: ->(importer) {
      ages = importer.values_at(:ages)
      genders = importer.values_at(:genders)
      categories = importer.values_at(:categories)
      ages_array = ages.to_a
      genders_array = genders.to_a
      categories_array = categories.to_a
      importer.batch_replace(:ages, ages_array)
      importer.batch_replace(:genders, genders_array)
      importer.batch_replace(:categories, categories_array)
    },
    template_object: ActiveAdminImport::Model.new(
      force_encoding: "UTF-8",
      csv_headers: ["id", "description", "retail_price", "wholesale_price", "notes", "name", "created_at", "updated_at", "image_file_name", "image_content_type", "image_file_size", "image_update_at", "genders", "ages", "categories", "all_categories", "refundable"]
    )

undefined method `values_at' for #ActiveAdminImport::Importer:0x007fe193b68e48

from active_admin_import.

Fivell avatar Fivell commented on August 29, 2024

@asalgan . What version of gem do you use? Try to update gem from git repo.
your Gemfile should contain line

gem "active_admin_import" , github: "activeadmin-plugins/active_admin_import"

from active_admin_import.

asalgan avatar asalgan commented on August 29, 2024

I updated my gemfile:

Error: undefined method `has_key?' for ["ages", "Array"]:Array

active_admin_import validate: false,
    on_duplicate_key_update: [:description, :retail_price, :wholesale_price, :notes],
    ignore: [:name, :created_at, :updated_at, :image_file_name, :image_content_type, :image_file_size, :image_update_at, :genders, :ages, :categories, :all_categories, :refundable],
    timestamps: false,
    before_batch_import: ->(importer) {
      ages = importer.values_at(:ages)
      genders = importer.values_at(:genders)
      categories = importer.values_at(:categories)
      ages_array = ages.to_a
      genders_array = genders.to_a
      categories_array = categories.to_a
      importer.batch_replace(:ages, ages_array)
      importer.batch_replace(:genders, genders_array)
      importer.batch_replace(:categories, categories_array)
    },
    template_object: ActiveAdminImport::Model.new(
      force_encoding: "UTF-8",
      csv_headers: ["id", "description", "retail_price", "wholesale_price", "notes", "name", "created_at", "updated_at", "image_file_name", "image_content_type", "image_file_size", "image_update_at", "genders", "ages", "categories", "all_categories", "refundable"]
    )

from active_admin_import.

Fivell avatar Fivell commented on August 29, 2024

@asalgan , the reason if it is your before_batch_import proc, what are you trying to do?
Try remove before_batch_import attribute.

from active_admin_import.

asalgan avatar asalgan commented on August 29, 2024

@Fivell I took it out:

active_admin_import validate: false,
    on_duplicate_key_update: [:description, :retail_price, :wholesale_price, :notes],
    ignore: [:id, :name, :created_at, :updated_at, :image_file_name, :image_content_type, :image_file_size, :image_updated_at, :genders, :ages, :categories, :all_categories, :refundable],
    timestamps: false,
    headers_rewrites: { :'ages' => :ages, :'genders' => :genders, :'categories' => :categories },
    template_object: ActiveAdminImport::Model.new(
      force_encoding: "UTF-8",
      csv_headers: ["id", "description", "retail_price", "wholesale_price", "notes", "name", "created_at", "updated_at", "image_file_name", "image_content_type", "image_file_size", "image_updated_at", "genders", "ages", "categories", "all_categories", "refundable"]
    )

Attribute was supposed to be a Array, but was a String. -- "genders"

I think it's because I have genders, ages, and categories set as enumerables in the model which saves them as arrays. What I'm trying to do is have someone be able to update a bunch of retail_price, wholesale_price, notes, and description values in the CSV, then re-upload it, so I'm doing a batch edit. I don't even want it to look at the other columns in the ignore list but putting them into "ignore" array above doesn't seem to do anything.

from active_admin_import.

asalgan avatar asalgan commented on August 29, 2024

@Fivell Ok I got this to work on localhost but for some reason not on production, basically I removed all the \r\n\ that were showing up. Then I used this:

active_admin_import validate: false,
    on_duplicate_key_update: [:description, :retail_price, :wholesale_price, :notes],
    timestamps: true,
    template_object: ActiveAdminImport::Model.new(
      force_encoding: "UTF-8"
    )

Which works in localhost, but for whatever reason in staging gives me this error:

Error: PG::UniqueViolation: ERROR: duplicate key value violates unique constraint "products_pkey" DETAIL: Key (id)=(715) already exists. : INSERT INTO "products" ("id","name","notes","created_at","u

Even though I have the on_duplicate_key_update line

from active_admin_import.

Fivell avatar Fivell commented on August 29, 2024

@asalgan , you can't use on_duplicate_key_update for PG, it's supported only by MySQL ,
Please use StackOverflow for support, I will close this ticket because it is not an issue

from active_admin_import.

asalgan avatar asalgan commented on August 29, 2024

@Fivell so does that mean I'm not given any options to use this gem if I'm using PG? I can't just use UPDATE because it tells me 'Unknown key'

from active_admin_import.

Fivell avatar Fivell commented on August 29, 2024

since this gem based on activerecord-import , there is 2 options

from active_admin_import.

asalgan avatar asalgan commented on August 29, 2024

sorry but I still can't get this to work for the life of me... I can't delete the existing records there are a lot of other records that depend on them. All I'm attempting to do is update the existing records rather than add new ones via CSV. Thanks for your help with all this

active_admin_import validate: false,
    timestamps: true,
    before_batch_import: proc { |importer|
      importer.csv_lines.map do |line|
        ActiveRecord::Base.transaction do
          Product.find(line.values_at(0).join.to_i).update_attributes(
            notes: line.values_at(2).join.to_s,
            description: line.values_at(5).join.to_s,
            retail_price: line.values_at(6).join.to_f,
            wholesale_price: line.values_at(11).join.to_f
          )
        end
      end
    },
    template_object: ActiveAdminImport::Model.new(
      force_encoding: "UTF-8",
    )

Error: PG::UniqueViolation: ERROR: duplicate key value violates unique constraint "products_pkey" DETAIL: Key (id)=(732) already exists. : INSERT INTO "products" ("id","name".....

from active_admin_import.

Fivell avatar Fivell commented on August 29, 2024

@asalgan , it is not supported by https://github.com/zdennis/activerecord-import gem.
I can suggest you to import your csv to another table and make raw sql update in after hook

from active_admin_import.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.