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

Error: this.warnMessageNoModelForKey is not a function #9611

Open
Gorzas opened this issue Nov 25, 2024 · 2 comments
Open

Error: this.warnMessageNoModelForKey is not a function #9611

Gorzas opened this issue Nov 25, 2024 · 2 comments
Labels
🏷️ bug This PR primarily fixes a reported issue

Comments

@Gorzas
Copy link

Gorzas commented Nov 25, 2024

Description & Reproduction

This is a problem that happens when running in not DEBUG mode, when the project build it's done for production (not staging). The issue happens when the REST Serializer tries to get the modelName from the root object returned from an API. The serializer doesn't find a model and tries to throw a warning:

const type = this.modelNameFromPayloadKey(modelName);
if (!store.schema.hasResource({ type })) {
warn(this.warnMessageNoModelForKey(modelName, type), false, {
id: 'ds.serializer.model-for-key-missing',
});
continue;
}

When trying to execute this.warnMessageNoModelForKey, this method doesn't exist because it's only added with DEBUG mode (!PRODUCTION, according to the code):

if (DEBUG) {
RESTSerializer.reopen({
warnMessageNoModelForKey(prop, typeKey) {
return (
'Encountered "' +
prop +
'" in payload, but no model was found for model name "' +
typeKey +
'" (resolved model name using ' +
this.constructor.toString() +
'.modelNameFromPayloadKey("' +
prop +
'"))'
);
},
});
}

The error could be happening in the last versions of Ember Data, according what I can see in the code. I understand this issue has low priority as Serializers/Adapters are deprecated in the last versions of the library.

Versions

ember-data v5.3.9
ember-source v5.8.0

@runspired
Copy link
Contributor

based on the git blame (and my own memory) that has been a debug only warning for ~7 years

image

(which would put it in the 1.x timeframe)

While there has been some recent (past year) changes to how we make the check to determine if the warning should be printed, the check has never guarded for production. For instance

image

What this means is that somehow you're the first to report a bug that should likely have been reported 7 years ago 🤦‍♂️

I'm willing to implement a fix for this as it would be relatively simple; however, the warning here is also telling you that in production you are receiving resources in payloads that you don't have models for. This is something I want to make a bit safer (since its nice to not unnecessarily blow up in prod) but this is far from the only location in the code which would result in an unknown resource generating an exception today. So you may find that the fix just punts the exception to a new location 🙈

If so, open a new issue for that one..

@runspired runspired added the 🏷️ bug This PR primarily fixes a reported issue label Nov 25, 2024
@runspired
Copy link
Contributor

this bug has been here since the first commit for it 10 years ago 0f5599b

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bug This PR primarily fixes a reported issue
Projects
Status: needs triage
Development

No branches or pull requests

2 participants