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
fix(dp): change response from 500 to 409 when existing serial number modified #12372
Conversation
Thanks for opening a PR! 💯
Howto
More infoPlease take a moment to read through the Magma project's
If this is your first Magma PR, also consider reading
|
Oops! Looks like you failed the Howto
♻️ Updated: ✅ The check is passing the Semantic PR after the last commit. |
@@ -216,6 +218,9 @@ func getHttpError(err error) error { | |||
case codes.NotFound: | |||
return echo.NewHTTPError(http.StatusNotFound, err) | |||
default: | |||
if strings.Contains(fmt.Sprintf("%s", err), duplicateRecordMsg) == true { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should not rely on error message (which can depend on database implementation), but instead return proper response code, by the servicers codes.AlreadyExists
especially, since handlers do not talk directly to the database and are not supposed to understand it.
So I would suggest updating also servicers (return proper error code codes.AlreadyExists
)
and db handlers (return proper error merrors.ErrAlreadyExists
)
be2d1de
to
e7bf1f1
Compare
Oops! Looks like you failed the Howto
♻️ Updated: ✅ The check is passing the DCO check after the last commit. |
e7bf1f1
to
ef4f85c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approving, just few small comments
|
||
cbsd1_payload = builder.build_post_data() | ||
cbsd2_payload = builder.build_post_data() | ||
cbsd1_payload["serial_number"] = "foo" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about adding this to the builder (with_serial_number
)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@@ -0,0 +1,40 @@ | |||
package sqorc |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it would be nice to have some tests for this file, since it's a library code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
orc8r/cloud/go/sqorc/builder.go
Outdated
@@ -50,6 +52,25 @@ func GetSqlBuilder() StatementBuilder { | |||
} | |||
} | |||
|
|||
// GetErrorChecker returns a squirrel Builder for the configured SQL dialect as | |||
// found in the SQL_DIALECT env var. | |||
func GetErrorChecker() ErrorChecker { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe move this to error checker file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@@ -43,6 +43,10 @@ func addColumns(builder sqorc.CreateTableBuilder, fields FieldMap) sqorc.CreateT | |||
colBuilder = colBuilder.Default(field.DefaultValue) | |||
} | |||
builder = colBuilder.EndColumn() | |||
|
|||
if field.Unique { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this work when there are multiple unique columns? Maybe add one simple test to query_test.go
for it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@@ -217,6 +217,8 @@ func getHttpError(err error) error { | |||
switch s, _ := status.FromError(err); s.Code() { | |||
case codes.NotFound: | |||
return echo.NewHTTPError(http.StatusNotFound, err) | |||
case codes.AlreadyExists: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe one small test for handlers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@@ -166,6 +166,8 @@ func makeErr(err error, wrap string) error { | |||
code := codes.Internal | |||
if err == merrors.ErrNotFound { | |||
code = codes.NotFound | |||
} else if err == merrors.ErrAlreadyExists { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe one small test for servicers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
e428c9b
to
981e14c
Compare
@magma/approvers-orc8r changes ready to merge, please have a look |
Signed-off-by: Wojciech Sadowy <wojciech.sadowy@freedomfi.com>
Signed-off-by: Wojciech Sadowy <wojciech.sadowy@freedomfi.com>
Signed-off-by: Wojciech Sadowy <wojciech.sadowy@freedomfi.com>
afcc5f1
to
45866b7
Compare
Signed-off-by: Wojciech Sadowy <wojciech.sadowy@freedomfi.com>
…modified (magma#12372) * fix(dp): return 409 in CRUD when cbsd serial number exists Signed-off-by: Wojciech Sadowy <wojciech.sadowy@freedomfi.com> * add more unit tests Signed-off-by: Wojciech Sadowy <wojciech.sadowy@freedomfi.com> * add setup and teardown to error checker tests Signed-off-by: Wojciech Sadowy <wojciech.sadowy@freedomfi.com> * integration test fix Signed-off-by: Wojciech Sadowy <wojciech.sadowy@freedomfi.com> Co-authored-by: Wojciech Sadowy <wojciech.sadowy@freedomfi.com>
Signed-off-by: Wojciech Sadowy wojciech.sadowy@freedomfi.com
When a CreateCbsd request was issued to backend with a serial_number of an existing cbsd, (Internal server error) 500 error was returned. The same was true for updating a cbsd with a serial number of an already existing serial number. Changed the error to Conflict (409).
Summary
Modified handlers.go
Test Plan
Integration tests added