-
Notifications
You must be signed in to change notification settings - Fork 112
[backend] Fix simulation to scenario grants #3055
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
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## release/current #3055 +/- ##
=====================================================
+ Coverage 41.20% 41.22% +0.01%
- Complexity 2286 2288 +2
=====================================================
Files 682 683 +1
Lines 20938 20944 +6
Branches 1424 1424
=====================================================
+ Hits 8628 8634 +6
Misses 11824 11824
Partials 486 486 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
.getGrants() | ||
.forEach( | ||
scenarioGrant -> { | ||
String key = scenarioGrant.getName() + "|" + scenarioGrant.getGroup(); |
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'm concerned we are reimplementing the table constraint in the service layer: I understand this is to avoid triggering a constraint violation while inserting new grants.
I'd be more concerned with findijng where in the app we are adding a duplicate grant that ultimately conflicts; is this about default grants?
Somehow this should perhaps be handled in the repository if this is not possible to reconcile in code: https://www.postgresql.org/docs/current/sql-insert.html#SQL-ON-CONFLICT
This is a Postgres-specific clause (i.e. not standard SQL) which can ignore an insert upon a constraint violation (by name), which would fit the bill here.
Since we reassign the saved grants after the inserts we would have deduplicated objects eventually in the java collection.
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 totally agree with you. I looked through the code and I don't understand how we got to this situation.
I had a recurring scenario, and the problem occurred at the end of the X recurrence.
However, I wasn't aware of SQL ON CONFLICT, which is much more appropriate. I'll look into it, thanks for the resource!
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.
@antoinemzs I found the root cause. I made some changes.
90e717d
to
702642d
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.
Cheers for finding a hole in our constraints !
error → "could not execute statement [ERROR: duplicate key value violates unique constraint "grant"\n Detail: Key (grant_group, grant_exercise, grant_name)=(d5d8c183-e6d9-4d47-b041-25e5f3bdbc62, 375280f3-7207-4f6b-95f8-2b1aaa480697, PLANNER) already exists.] [insert into grants (grant_exercise,grant_group,grant_name,grant_scenario,grant_id) values (?,?,?,?,?)]"