Skip to content

feat: improved error reporting on associations - #14901

Merged
WikiRik merged 3 commits into
sequelize:mainfrom
baileykue:improve-subclass-error
Nov 5, 2022
Merged

WikiRik merged 3 commits into
sequelize:mainfrom
baileykue:improve-subclass-error

Conversation

@baileykue

Copy link
Copy Markdown
Contributor

Pull Request Checklist

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

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

Description Of Change

This improves the error reporting on associations by telling us what exactly is
not a proper subclass of the Sequelize Model. This assists in debugging and
should present little risk to the existing behavior.

Possibly due to #14161 I was not able to get the full test suite running
locally before I made any local changes. However, the number of tests that
were failing (2) remained the same after my changes, and the failing tests had
more to do with SQLite than changes to the model structure.

Thanks for maintaining such an awesome open source project!

Comment thread src/associations/helpers.ts Resolved

@WikiRik WikiRik left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The four comments are about the same thing.

The styling changes have made it more difficult to review this PR, but I've went through it all and did not see any other changes so we should be okay

Comment thread test/unit/associations/has-one.test.ts Resolved
Comment thread test/unit/associations/has-many.test.ts Resolved

@ephys ephys left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR. That error message definitely deserved some improvements

I'm sorry to ask this but could you revert the stylistic changes? They increase the risk of conflict with the other PRs, make this PR more difficult to read as well the the commit history. We'd like to restrict style changes to PRs dedicated to that.

Comment thread src/associations/helpers.ts Resolved
This improves the error reporting on associations by telling us what exactly is
not a proper subclass of the Sequelize Model. This assists in debugging and
should present little risk to the existing behavior.

Possibly due to sequelize#14161 I was not able to get the full test suite running
locally _before_ I made any local changes. However, the number of tests that
were failing (2) remained the same after my changes, and the failing tests had
more to do with SQLite than changes to the model structure.
@baileykue
baileykue force-pushed the improve-subclass-error branch from a06b558 to 3e7a015 Compare September 27, 2022 18:32

@WikiRik WikiRik left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a small readability suggestion.

Also, can you look into the previous comment as well?

You're thinking we should have two paths here for the error message: One for when the error is clearly incorrect (null or undefined) vs. another when the object passed is not a subclass of Sequelize.Model.

Something like this between the two error messages?

For undefined et. al:

`User.hasOne` called with undefined but needs to be an object that is a subclass of `Sequelize.Model`

For an object that's not the right subclass:

`User.hasOne` called with an object that's not a subclass of `Sequelize.Model`

Comment thread test/unit/associations/has-many.test.ts Resolved
Comment thread test/unit/associations/has-one.test.ts Resolved
ephys
ephys previously approved these changes Nov 5, 2022

@ephys ephys left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once @WikiRik's style changes have been applied, this should be good to go :)

@WikiRik WikiRik left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've gone ahead and committed my suggestion so we should be good to go! Thanks for working on this!

@WikiRik
WikiRik merged commit 8e3c626 into sequelize:main Nov 5, 2022
@LoganBarnett

Copy link
Copy Markdown

@WikiRik thanks so much for dragging this over the finish line! We got pretty caught up with some work duties.

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.

5 participants