Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

what does Error during import: mean? #88

Closed
jstoebel opened this issue Mar 22, 2017 · 6 comments
Closed

what does Error during import: mean? #88

jstoebel opened this issue Mar 22, 2017 · 6 comments

Comments

@jstoebel
Copy link

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:in raise_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
Copy link

joaku commented May 15, 2017

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

@joaku
Copy link

joaku commented May 19, 2017

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

@karanbeniwal
Copy link

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
Copy link
Collaborator

Thanks. I added a note in the README

@Chadh13
Copy link

Chadh13 commented Jan 17, 2019

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

  • Ruby 2.5.3
  • Rails 5.2.2

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
Copy link
Collaborator

Thanks @Chadh13

I added this suggestion to the readme

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants