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

fix(dp): change response from 500 to 409 when existing serial number modified #12372

Merged
merged 4 commits into from Apr 8, 2022

Conversation

WojSad
Copy link
Contributor

@WojSad WojSad commented Apr 1, 2022

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

@WojSad WojSad requested review from a team and sklgromek April 1, 2022 12:13
@pull-request-size pull-request-size bot added the size/M Denotes a PR that changes 30-99 lines. label Apr 1, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Apr 1, 2022

Thanks for opening a PR! 💯

A couple initial guidelines

Howto

  • Reviews. The "Reviewers" listed for this PR are the Magma maintainers who will shepherd it.
  • Checks. All required CI checks must pass before merge.
  • Merge. Once approved and passing CI checks, use the ready2merge label to indicate the maintainers can merge your PR.

More info

Please take a moment to read through the Magma project's

If this is your first Magma PR, also consider reading

@github-actions
Copy link
Contributor

github-actions bot commented Apr 1, 2022

Oops! Looks like you failed the Semantic PR check.

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 {
Copy link
Contributor

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)

@WojSad WojSad force-pushed the crud-response-status-fix branch 2 times, most recently from be2d1de to e7bf1f1 Compare April 6, 2022 10:07
@WojSad WojSad requested review from a team and hcgatewood April 6, 2022 10:07
@pull-request-size pull-request-size bot added size/L Denotes a Pull Request that changes 100-499 lines. and removed size/M Denotes a PR that changes 30-99 lines. labels Apr 6, 2022
@github-actions github-actions bot added the component: orc8r Orchestrator-related issue label Apr 6, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Apr 6, 2022

Oops! Looks like you failed the DCO check. Be sure to sign all your commits.

Howto

♻️ Updated: ✅ The check is passing the DCO check after the last commit.

@github-actions
Copy link
Contributor

github-actions bot commented Apr 6, 2022

feg-workflow

    2 files  202 suites   38s ⏱️
370 tests 370 ✔️ 0 💤 0
384 runs  384 ✔️ 0 💤 0

Results for commit b18d618.

♻️ This comment has been updated with latest results.

Copy link
Contributor

@jkmar jkmar left a 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"
Copy link
Contributor

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)?

Copy link
Contributor Author

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
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -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 {
Copy link
Contributor

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

Copy link
Contributor Author

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 {
Copy link
Contributor

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

Copy link
Contributor Author

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:
Copy link
Contributor

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

Copy link
Contributor Author

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 {
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@github-actions
Copy link
Contributor

github-actions bot commented Apr 6, 2022

cloud-workflow

    7 files  352 suites   2m 8s ⏱️
966 tests 966 ✔️ 0 💤 0

Results for commit b18d618.

♻️ This comment has been updated with latest results.

@github-actions
Copy link
Contributor

github-actions bot commented Apr 6, 2022

agw-workflow

     77 files     122 suites   7m 23s ⏱️
1 134 tests 1 125 ✔️ 9 💤 0
1 135 runs  1 126 ✔️ 9 💤 0

Results for commit b18d618.

♻️ This comment has been updated with latest results.

@WojSad WojSad force-pushed the crud-response-status-fix branch 2 times, most recently from e428c9b to 981e14c Compare April 7, 2022 10:42
@WojSad WojSad changed the title fix(dp): change response from 500 to 400 when existing serial number modified fix(dp): change response from 500 to 409 when existing serial number modified Apr 7, 2022
@WojSad
Copy link
Contributor Author

WojSad commented Apr 8, 2022

@magma/approvers-orc8r changes ready to merge, please have a look

Wojciech Sadowy added 3 commits April 8, 2022 15:38
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>
Signed-off-by: Wojciech Sadowy <wojciech.sadowy@freedomfi.com>
@WojSad WojSad merged commit 5bca245 into magma:master Apr 8, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Apr 8, 2022

Unit Test Results

157 files  157 suites   2h 3m 4s ⏱️
308 tests 305 ✔️ 3 💤 0

Results for commit 5bca245.

♻️ This comment has been updated with latest results.

@WojSad WojSad deleted the crud-response-status-fix branch May 25, 2022 07:37
emakeev pushed a commit to emakeev/magma that referenced this pull request Aug 5, 2022
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: orc8r Orchestrator-related issue size/L Denotes a Pull Request that changes 100-499 lines.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants