Closed hstoebel closed 6 years ago
Any solution to this? I have the exact same problem. I think it might be trying to create instead of accesing it.
I found the solution. I shutted down the server and restarted. After that, it started working the import.
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.
Repeat each time you make any changes to your code.
Thanks. I added a note in the README
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:
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.
Thanks @Chadh13
I added this suggestion to the readme
In my models I have an
AssessmentItem
whichhas_many :items_levels
. When I try to import anItemLevel
I get the errorError 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!