-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Error when upgrading from 3.24 to 3.28 when a model has an isValid
property
#7897
Comments
So it appears the issue here is that mirage looks up models and accesses the static properties on them without using the container. This has a number of ill-effects and was never officially supported though it is something we felt we need to explicitly deprecate. The deprecation RFC is here: emberjs/rfcs#741 and this second RFC was also motivated by the sort of bug discovered here. emberjs/rfcs#738 All this to say that I'm not surprised that this lookup results in Prior reading on this and a related bug in Ember:
BUT! While I'm not surprised at the pathology of this triggering, it does mean we had a blind spot around it being able to be triggered by collisions with the properties that are on Model out of the box. Those properties are intended to be overridable and not being so would even harm the implementation of the Links & Attrs RFC that @mansona is currently working on in #7855 I built this twiddle to show that native class syntax does not have this issue but classic syntax does. This means that folks who hit this bug can resolve it by refactoring to native syntax import Model, { attr } from '@ember-data/model';
class User extends Model {
@attr isValid;
}
/*
// replace the class definition with this one to trigger the error
const User = Model.extend({
isValid: attr(),
});
*/
const attrs = User.attributes;
console.log(attrs);
export default User; |
Since it can also be worked around by changing the attribute name (if not intentionally overriding) and native-class syntax is the way-forward, I'm comfortable closing this issue (but will leave it open for you to do so if you agree). Thanks for looking into this and writing it up so clearly! |
When upgrading an app from 3.24 to 3.28, I saw an error:
(For anyone searching -- in tests, without
No try/catch
checked this presented as mirage failing to start).I tracked this down to an
isValid
computed property defined in Ember classic syntax on a model.Renaming the computed property from
isValid
to anything else removes the error. I have no problem just renaming, but was surprised that the user-definedisValid
interfered with something called by ember-data.The text was updated successfully, but these errors were encountered: