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

Multiple GlobalSettings rows, bad use of .findOne() #987

Closed
michaelbromley opened this issue Jul 14, 2021 · 0 comments
Closed

Multiple GlobalSettings rows, bad use of .findOne() #987

michaelbromley opened this issue Jul 14, 2021 · 0 comments
Assignees
Labels
type: bug 🐛 Something isn't working @vendure/core

Comments

@michaelbromley
Copy link
Member

Describe the bug
In Slack it was reported that a user had somehow ended up with multiple rows in the GlobalSettings table. This Should Never Happen™. As a result of this, when attempting to update global settings, Vendure (postgres) would randomly pick one of the rows and update it, making it look like the changes were not saved.

To Reproduce
No idea how to reproduce creating multiple rows. However, on investigation I found that the use of .findOne() with no argument is incorrect. I had assumed that it would be fine since there should only every be 1 row. Turns out the current behaviour is not to be relied upon and, in the case that somehow multiple rows get created, it leads to the failure described above.

Expected behavior
There should only be 1 global settings row. If somehow more are created, only a single one should ever be selected, in a deterministic way.

2 points to fix:

  1. Include some error-correcting code that will enforce only 1 row existing.
  2. Don't use empty .findOne(). Make it deterministic with some query criteria, eg. get the earliest created.

Environment (please complete the following information):

  • @vendure/core version: 1.1.0
  • Nodejs version: any
  • Database (mysql/postgres etc): postgres
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug 🐛 Something isn't working @vendure/core
Projects
None yet
Development

No branches or pull requests

1 participant