emberjs / data

WarpDrive is a lightweight data library for web apps — universal, typed, reactive, and ready to scale.
https://api.emberjs.com/ember-data/release
MIT License
3.04k stars 1.33k forks source link

Error: this.warnMessageNoModelForKey is not a function #9611

Open Gorzas opened 1 day ago

Gorzas commented 1 day ago

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:

https://github.com/emberjs/data/blob/8553b7728b31f5a409d0e98e21e113687371a48c/packages/serializer/src/rest.js#L279-L285

When trying to execute this.warnMessageNoModelForKey, this method doesn't exist because it's only added with DEBUG mode (!PRODUCTION, according to the code): https://github.com/emberjs/data/blob/8553b7728b31f5a409d0e98e21e113687371a48c/packages/serializer/src/rest.js#L797-L813

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 commented 1 day ago

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 commented 1 day ago

this bug has been here since the first commit for it 10 years ago https://github.com/emberjs/data/commit/0f5599b4eded2d658bef9f86ff860e4c03ebdeac