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

constructor.modelName is null in 2.12.1 #4923

Closed
BryanCrotaz opened this issue Apr 12, 2017 · 23 comments
Closed

constructor.modelName is null in 2.12.1 #4923

BryanCrotaz opened this issue Apr 12, 2017 · 23 comments

Comments

@BryanCrotaz
Copy link
Contributor

Seeing this on objects pushed into the store. Don't have a full robust reproduction step yet, but I've now seen this across four different apps.

model.constructor.modelName is null
model._internalModel.modelName is correct

@cloke
Copy link

cloke commented Apr 13, 2017

I've been seeing this as well. Are you using Emberfire in your project? I noticed that some of my requests seem to now be routing through the ember fire adapter (possibly a different issue) and they use the following code which causes the issue.

              var modelName = record.constructor.modelName;
              var adapter = _this.adapterFor(modelName);

The weird part for me is it doesn't happen 100% of the time so I am still digging into the code.

@bmac
Copy link
Member

bmac commented Apr 14, 2017

@BryanCrotaz and @cloke, I've been trying to reproduce the issue locally but so far have been unsuccessful. If you get any closer to identifying a reproduction test case I would appreciate it.

@BryanCrotaz
Copy link
Contributor Author

I'm not using EmberFire, but we have similar code.

As a workaround use

var modelName = record.constructor.modelName || record._internalModel.modelName;

@runspired
Copy link
Contributor

The key thing here is which Ember version. cc @bmac @BryanCrotaz @cloke

@cloke
Copy link

cloke commented Apr 14, 2017

We are on version 2.12.1. It seems like it appeared in in 2.12, but I am not 100% certain. It's been a really weird one to track down. We have a fix in place for our code, but it becomes a problem with a few of our add-ons like EmberFire.

@runspired
Copy link
Contributor

runspired commented Apr 14, 2017

@cloke just to confirm

Ember 2.12.x
paired with Ember Data: 2.12.x ?

@cloke
Copy link

cloke commented Apr 14, 2017

[Debug] DEBUG: Ember: 2.12.1
[Debug] DEBUG: Ember Data: 2.12.2
[Debug] DEBUG: Firebase: 3.7.6
[Debug] DEBUG: EmberFire: 0.0.0
[Debug] DEBUG: jQuery: 3.2.0
[Debug] DEBUG: Ember Simple Auth: 1.2.1

@stefanpenner
Copy link
Member

This seems a tad tricky without a reproduction. If we can be provided one, this should be more actionable to diagnose.

@workmanw
Copy link

workmanw commented Apr 14, 2017

This is likely an issue with the factoryFor changes and emberfire. We had this issue with ember-data-model-fragments. I bet if you search emberfire, you'll find it's looking up and/or registering a new factory. Possibly related to: #4810

EDIT: Actually maybe I'm wrong here. A quick search of their code base didn't turn up any usage of factoryFor, _modelFor, or modelFactoryFor. I did see a very similar issue while working to make ember-data-model-fragments compatible with 2.12.

@BryanCrotaz
Copy link
Contributor Author

It's not emberfire. We're not using it. We are doing a lot of store.push though

@workmanw
Copy link

@BryanCrotaz D'oh. I'm sorry. I read the messages out of order via email and it got stuck in my head you were.

@runspired
Copy link
Contributor

There's a known issue with 2.12 + 2.12 with modelName's being wrong for re-exports (or multiple registrations of the same base model). TL;DR last one in wins.

However, the only cases I've found where modelName was itself null had to do with incorrect use of getters on modelName. Here's a twiddle from when I debugged this a few months ago, I thought we'd caught everything and gotten it fixed though.

https://ember-twiddle.com/0ce04900a6219d8dd18d2ddeafaa9658?openFiles=templates.application.hbs%2C

Against Ember Data 2.12 Using Ember:

2.9.1: 👍
2.10.2 & 2.11.1 & 2.12.0 modelClass.modelName cannot be bound to in a template (modelClass.get('modelName') will also fail.

This was expected. I wonder if this is the behavior folks are hitting.

@BryanCrotaz
Copy link
Contributor Author

modelName2 in your example is where I'm seeing null

@cloke
Copy link

cloke commented Apr 18, 2017

I ended up reverting back to ember and data 2.11 and all my issues went away. The issue revolves around a situation where record.constructor.modelName is null in 2.12 and not in 2.11. I am able to work around that in my own code, but some of the add-ons we use also use record.constructor.modelName which made working around the problem much more difficult.

@runspired
Copy link
Contributor

@cloke did you see this in ED 2.12 with Ember 2.11? Because if so that would conclusively point us to there being a separate issue to any known ones.

@cloke
Copy link

cloke commented Apr 18, 2017

@runspired I just updated ED to 2.12, but left ember to 2.11 and the issue returned.

record.constructor.modelName with this combination becomes null.

@runspired
Copy link
Contributor

@cloke if you wouldn't mind, could we screenhero tomorrow and throw a debugger on one of these?

@knownasilya
Copy link
Contributor

knownasilya commented Apr 28, 2017

I might have a similar issue because queries resolve, but the content is empty, even though the payload had the data. Works in ED 2.11.x but not in 2.12 with Latest Ember version.

@runspired
Copy link
Contributor

@knownasilya the easy fix is if you are re-exporting the same model multiple places, change it like so:

export { default } from './foo-model';

becomes.

import FooModel from './foo-model';
export default FooModel.extend({});

@runspired
Copy link
Contributor

(also fwiw this fix is also what the deprecation you will soon receive will tell you to do and do for you)

@abhishek97
Copy link

+1

@runspired
Copy link
Contributor

Related but stalled PR: #4886

@runspired
Copy link
Contributor

Closing as modelName issues have been resolved.

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

No branches or pull requests

8 participants