You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Creating a record with the same value in a column that is Unique:true. I'm using FeathersJS with uses Sequelize. I successfully inserted new record via restful api using Postman. However if I send the same request again( create a user with the same email which the column is unique) it crashes the server with error "TypeError: Cannot read property '2' of null".
So last night I tried to replicate the issue in my home environment since this was at work, and it worked! Sooo.... I assumed perhaps the installation of node_modules went wrong since my workplace has a lot of firewalls and strict security. But after reinstalled dependencies I still got the issue.
The DB at my home env is 5.6.x and I doubt Mysql version is the issue so I looked at my node version found I'm using v4.2.1 @ work. This is a red flag since FeatherJS documentation is stating nodeV 5+ and if anything is below is required to use babel.
Not sure if this is related to this issue but I will work on updating my node and see if that fixes the issue.
I'm actually pretty sure the mysql version is the issue then - We've had these kind of problems in the past where the error message as different between different versions of mysql.
I think moving forward we should abstract the code that parses messages into a separate method that we can then easily unit test. There is no need to actually run tests against several different versions, but we'd like to be able to support them and at least not crash still :)
@janmeier I can also confirm that mysql version is the issue. Luckily the mysql version locally installed at work is version 5.6.15 VS. the mysql 5.7.13 where I got this issue.
I replicated both table structures and unique indexes as seen below. Sent a POST to create a new record and immediately sent the POST again to recreate the crash but this time the server did not crash and instead got a JSON error as expected.
Expected Response with mysql version 5.6.15 { "test_description": "b2b_edgeFlow_creditCard_visa_splitpayment_3", "status": "failed", "build_date": "2016-08-01 15:20:28" }
@crzidea Some details please? Which mysql version, and what is the wording of the message? As i've already mentioned before we need to know the actual wording of the error message to be able to support it
this is because that:
you save a data like 'cccc\r',so the err.message is ''Duplicate entry 'cccc\r' for key ...",then,the method match return null.
please replace('\r','') before you create()
Activity
felixfbecker commentedon Oct 19, 2016
That stack trace does not mention sequelize anywhere. If you still believe this is a sequelize bug, create an SSCCE. You can find a template here
janmeier commentedon Oct 20, 2016
@felixfbecker Actually it does ;), here
@abartolo Which language is your mysql installation? Currently we only support parsing messages in english?
In any case, we need a guard before accessing the match, checking if anything was actually matched
felixfbecker commentedon Oct 20, 2016
Sorry, overlooked that on the screenshot.
abartolo commentedon Oct 20, 2016
@janmeier Mysql is installed in english.
So last night I tried to replicate the issue in my home environment since this was at work, and it worked! Sooo.... I assumed perhaps the installation of node_modules went wrong since my workplace has a lot of firewalls and strict security. But after reinstalled dependencies I still got the issue.
The DB at my home env is 5.6.x and I doubt Mysql version is the issue so I looked at my node version found I'm using v4.2.1 @ work. This is a red flag since FeatherJS documentation is stating nodeV 5+ and if anything is below is required to use babel.
Not sure if this is related to this issue but I will work on updating my node and see if that fixes the issue.
janmeier commentedon Oct 20, 2016
I'm actually pretty sure the mysql version is the issue then - We've had these kind of problems in the past where the error message as different between different versions of mysql.
I think moving forward we should abstract the code that parses messages into a separate method that we can then easily unit test. There is no need to actually run tests against several different versions, but we'd like to be able to support them and at least not crash still :)
abartolo commentedon Oct 20, 2016
@janmeier I can also confirm that mysql version is the issue. Luckily the mysql version locally installed at work is version 5.6.15 VS. the mysql 5.7.13 where I got this issue.
I replicated both table structures and unique indexes as seen below. Sent a POST to create a new record and immediately sent the POST again to recreate the crash but this time the server did not crash and instead got a JSON error as expected.
Expected Response with mysql version 5.6.15
{ "test_description": "b2b_edgeFlow_creditCard_visa_splitpayment_3", "status": "failed", "build_date": "2016-08-01 15:20:28" }Both have the same Table and Indexes

Indexes

janmeier commentedon Oct 24, 2016
Could you post the different error messages?
abartolo commentedon Oct 24, 2016
@janmeier Not sure what you mean. I get the same error I originally posted.
https://cloud.githubusercontent.com/assets/5394228/19537833/7c84e15c-961f-11e6-9f0e-ec5aaa9a72f3.png
janmeier commentedon Oct 24, 2016
I mean that actually error messages from MySQL - so the code can be fixed to support both
crzidea commentedon Dec 22, 2016
I got the exactly issue with this. Any update?
janmeier commentedon Dec 22, 2016
@crzidea Some details please? Which mysql version, and what is the wording of the message? As i've already mentioned before we need to know the actual wording of the error message to be able to support it
akhoury commentedon Apr 20, 2018
this is till happening when I try to update a record with a column (that is set to
unique:true) with a non unique value,akhoury commentedon Apr 21, 2018
The issue is here:
sequelize/lib/dialects/mysql/query.js
Lines 199 to 212 in f8a98a1
I put a log statement to see the
errand it looks like this.There is no
err.messagesomatchisnull, and there are 2 statements that don't guard against it.and
I am using
MySQL 5.7.21Wadeck commentedon Aug 16, 2018
Same error here, using MySQL in french, exception is "Duplicata du champ 'UC....-UC....-xxx' pour la clef '<key_name> etc.
The approach to use the translated name in the trace does not seem really stable :(
zhangshichun commentedon Jan 5, 2019
this is because that:
you save a data like 'cccc\r',so the err.message is ''Duplicate entry 'cccc\r' for key ...",then,the method match return null.
please replace('\r','') before you create()