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: Enables translate error property of gorm #877

Merged
merged 1 commit into from
Sep 15, 2023

Conversation

NeerajGartia21
Copy link
Collaborator

Description of your changes

Fixes #

I have:

  • Read and followed KubeVela's contribution process.
  • Related Docs updated properly. In a new feature or configuration option, an update to the documentation is necessary.
  • Run yarn lint to ensure the frontend changes are ready for review.
  • Run make reviewableto ensure the server changes are ready for review.
  • Added backport release-x.y labels to auto-backport this PR if necessary.

Special notes for your reviewer

@NeerajGartia21 NeerajGartia21 changed the title Enables translate error property of gorm Fix: Enables translate error property of gorm Sep 14, 2023
@codecov
Copy link

codecov bot commented Sep 14, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: +0.03% 🎉

Comparison is base (d14a2b6) 58.98% compared to head (705fe8b) 59.01%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #877      +/-   ##
==========================================
+ Coverage   58.98%   59.01%   +0.03%     
==========================================
  Files         116      116              
  Lines       19844    19846       +2     
==========================================
+ Hits        11704    11713       +9     
+ Misses       6703     6698       -5     
+ Partials     1437     1435       -2     
Flag Coverage Δ
apiserver-unittests 32.60% <100.00%> (+0.01%) ⬆️
server-e2e-tests 48.33% <0.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Changed Coverage Δ
pkg/server/infrastructure/datastore/mysql/mysql.go 68.42% <100.00%> (+1.75%) ⬆️
...rver/infrastructure/datastore/postgres/postgres.go 72.72% <100.00%> (+1.29%) ⬆️

... and 8 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@chivalryq
Copy link
Member

What is this field used for?

@NeerajGartia21
Copy link
Collaborator Author

Sorry, I forgot to put that in the description. This is actually a bug. TranslateError field if enabled translates the error returned by the gorm drivers to gorm specific errors like ErrOnDuplicateKey. In our code we are using it here -

if match := errors.Is(dbAdd.Error, gorm.ErrDuplicatedKey); match {
			return datastore.ErrRecordExist
		}
		return datastore.NewDBError(dbAdd.Error)

Without translation we can't compare both the error and hence it's causing a bug. More info can be found here - https://gorm.io/docs/error_handling.html#Dialect-Translated-Errors

Copy link
Member

@chivalryq chivalryq left a comment

Choose a reason for hiding this comment

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

LGTM

@chivalryq chivalryq merged commit 4579408 into kubevela:main Sep 15, 2023
15 of 16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants