fix(truncate): fix missing await in truncate all model with cascade#12660
fix(truncate): fix missing await in truncate all model with cascade#12660bmeriaux wants to merge 1 commit into
Conversation
Codecov Report
@@ Coverage Diff @@
## master #12660 +/- ##
==========================================
+ Coverage 96.32% 96.33% +0.01%
==========================================
Files 95 95
Lines 9261 9262 +1
Branches 90 90
==========================================
+ Hits 8921 8923 +2
+ Misses 323 322 -1
Partials 17 17
Continue to review full report at Codecov.
|
78225a8 to
1e8dddd
Compare
|
Hello! Thanks for catching this! Please fix the tests and I will merge, thanks! |
1e8dddd to
cd886a0
Compare
|
MariaDb and MySQL tests are failing because of the foreign key, which require to truncate in cascade, so it seems to not have the cascade set properly ? is it. another issue because i didn't touch anything specific to an implementation |
|
@bmeriaux Hmmm... Probably the fact that it was not being awaited caused the error to not be caught by CI. I agree this does not seem your fault. Do you have any idea how to solve it, though? |
After reading the MySQL doc, it does not support truncate with cascade on foreign key, so how to proceed ? add a if on dialect for the option to do a bulkDelete for maria and mysql ? |
|
for. what i see here: https://dev.mysql.com/doc/refman/8.0/en/truncate-table.html and here: https://docs.microsoft.com/en-us/sql/t-sql/statements/truncate-table-transact-sql?view=sql-server-ver15
|
9d9df16 to
92bcc01
Compare
|
Let me ping @jedwards1211, maybe he will have an idea of why this |
without it, i have a lot of deadlock error with postgres when truncating models with foreign key in cascade, because multiple truncate try to cascade on the same reference table at the same time |
|
Thanks for the investigation @bmeriaux, intuitively I think your first bullet is the best option, but can you please do an extra investigation: does the sequelize documentation claim anything about truncate working or not working in mysql/mariadb/mssql? We must give users whatever our docs says (or, maybe, change the docs) |
Yes, I am sure the |
92bcc01 to
80eefcc
Compare
|
i added an option in dialect support |
80eefcc to
5bb141f
Compare
|
Do you know where the original code went? I don't see any missing awaits in the diff...seems totally plausible that one was missing though because there were a few heisenbugs in the refactoring |
@bmeriaux Yeah, that's fine, if the underlying database does not support it, it is ok to have an error in Sequelize as well. |
|
@jedwards1211 It's this line in |
6985082 to
415b3d8
Compare
|
finally, i removed the "best effort" to support truncate with cascade option set to true for dialect which does not support it, |
843c1e4 to
916d7b8
Compare
|
okay, yup I don't remember if I automated that case of refactoring or not but if so, what must have tripped it up is that the iteratee was declared as a separate variable instead of provided as an inline function. I looked over the rest of that commit for good measure and didn't manage to find any other mistakes like this at least |
|
@jedwards1211 Hmm, I see. Can you give me the link to that commit? I'd like to take a look too |
|
@bmeriaux Thanks again for the great work!! I want to make sure nothing here is a breaking change, I want to make more tests and take a closer look at the code (not only your changes but look at how things worked before), so I will not merge this PR yet. However, since it is very obvious that this missing
I will merge those two as long as they don't break any existing tests, since it is very obvious that the This way your issue is fixed asap while I don't risk making breaking changes unexpectedly. |
|
… do no support it
4583bb1 to
961926c
Compare
|
I rebased this one on master |
|
Hey there :) First of all: Thanks a bunch for your contribution to Sequelize! Much appreciated! A couple of months ago, we have switched from master to main branch as our primary development branch and hence this PR is now outdated :( If you still think this change is making sense, please consider recreating the PR against ✌️ |
Pull Request check-list
Please make sure to review and check all of these items:
npm run testornpm run test-DIALECTpass with this change (including linting)?Description of change
Fix a missing
awaitinsequelize.truncatewithcascadeoption. Without it, all models try to truncate in parallel which triggers a deadlock when 2 models truncate the same child model.