Skip to content

Display message when passing include's model as null/undefined - #10426

Closed
serge1peshcoff wants to merge 1 commit into
sequelize:masterfrom
serge1peshcoff:fix-include-crash-on-undefined
Closed

serge1peshcoff wants to merge 1 commit into
sequelize:masterfrom
serge1peshcoff:fix-include-crash-on-undefined

Conversation

@serge1peshcoff

@serge1peshcoff serge1peshcoff commented Feb 8, 2019 •

Copy link
Copy Markdown

Pull Request check-list

Please make sure to review and check all of these items:

  • Does npm run test or npm run test-DIALECT pass with this change (including linting)?
  • Does the description below contain a link to an existing issue (Closes #[issue]) or a description of the issue you are solving?
  • Have you added new tests to prevent regressions?
  • Is a documentation update included (if this change modifies existing APIs, or introduces new ones)? - no API changes here
  • Did you follow the commit message conventions explained in CONTRIBUTING.md?

Description of change

For now, if you use include and pass the null/undefined as a parameter (for example, in case of a typo, happened to me actually) it would crash with Cannot read property '_pseudo of undefined error, which can be not obvious. I've changed it so it'd through the error if the passed object is not truthy and also provided a test for it.

Here's the example of the issue: https://stackoverflow.com/questions/41790321/sequelize-error-unhandled-rejection-typeerror-cannot-read-property-pseudo-of

Example:

const User = sequelize.define('User', {}); // declaring the model
User.findAll({ include: [{
    model: null
]} }); // would throw an error

@SimonSchick

Copy link
Copy Markdown
Contributor

This seems like an anti pattern, the developer should ensure the data structure is correct, if sequelize would validate every incorrectly passed property the code base would be 10x the size it is now.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants