stephskardal / rails_admin_import

Rails Admin Import functionality
http://www.endpoint.com/
MIT License
160 stars 122 forks source link

what does `Error during import:` mean? #88

Closed hstoebel closed 6 years ago

hstoebel commented 7 years ago

In my models I have an AssessmentItem which has_many :items_levels. When I try to import an ItemLevel I get the error Error during import: AssessmentItem(#70286054976500) expected, got AssessmentItem(#70286114743280) (/Users/stoebelj/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-4.2.7.1/lib/active_record/associations/association.rb:218:inraise_on_type_mismatch!')` The parent record exists and I am referencing it with the correct mapping key.

Can someone give me an idea of what this error means and what might be the culprit?

Thanks!

joaku commented 7 years ago

Any solution to this? I have the exact same problem. I think it might be trying to create instead of accesing it.

joaku commented 7 years ago

I found the solution. I shutted down the server and restarted. After that, it started working the import.

karanbeniwal commented 7 years ago

I's too having this problem.

Since, in development environment, each time you make changes to class and save it in any editor, the class is registered as a new class and hence the mismatch of class' object instances.

  1. Stop rails server
  2. Run it again
  3. Reload your page
  4. Now, try uploading again

Repeat each time you make any changes to your code.

monkbroc commented 6 years ago

Thanks. I added a note in the README

Chadh13 commented 5 years ago

I'm commenting on this in order to add information in hopes of preventing anyone else in the future from dumping hours into debugging this like I did.

As of 2 days ago imports stopped working on my local machine while it was still working on our Heroku environments without issue. My local and our heroku apps had code parity. After a day and a half of walking back through previous states of the code commit by commit, pulling fresh database copies, busting caches, and searching for related incidents, I finally got this resolved on my local.

config.cache_classes = true must now be set to true in your development.rb for Rails Admin Import to successfully import.

Screenshot of the error: web image 2019-01-17 17-32-05

This was taking place for me while attempting to import a model which has an associated belongs_to.

Rails Env

Error during import: expected (), got () which is an instance of (model) The core cause of this error message is because classes are being reloaded mid-request, and that results in the models you are attempting to import, find, update, or reference were re-initialized a 2nd time during the import and that re-assigns new instance IDs to your models.

Here is a related thread that describes this phenomenon: https://stackoverflow.com/questions/15909663/associationtypemismatch-for-the-same-model

Additional Note: Although I'm almost certain that I had changed that environment value to true and tested that on my local (several times) before it actually started working, I have verified that changing that value to false immediately reproduces the same error as I posted above; and that changing it back to true results in a successful import. My best guess here is that I had some sort of caching (bootsnap maybe?) active when I changed the value the first times and so the value being booted with never actually changed, even though I had updated my config/environments/development.rb file.

monkbroc commented 5 years ago

Thanks @Chadh13

I added this suggestion to the readme