-
Notifications
You must be signed in to change notification settings - Fork 189
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: NotNullConstraintViolation when sharing with users #1406
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Codecov Report
@@ Coverage Diff @@
## master #1406 +/- ##
============================================
+ Coverage 91.86% 91.87% +0.01%
Complexity 751 751
============================================
Files 63 63
Lines 2752 2745 -7
============================================
- Hits 2528 2522 -6
+ Misses 224 223 -1
Continue to review full report at Codecov.
|
This is done to set the id to null BEFORE resetting the updated fields. The purpose of this is to avoid explicitly adding a NULL id into the DB, which provokes an error in some DBMS (like postgres). Fixes nextcloud#1375 Signed-off-by: Marco Nassabain <[email protected]>
Signed-off-by: Marco Nassabain <[email protected]>
SMillerDev
approved these changes
Jun 13, 2021
Grotax
added a commit
that referenced
this pull request
Jun 16, 2021
Changed - added feed search (#1402) Fixed - removed reference for deleted repair-steps (#1399) - Fix NotNullConstraintViolation when sharing news items with users (#1406) Signed-off-by: Benjamin Brahmer <[email protected]>
Merged
Grotax
added a commit
that referenced
this pull request
Jun 16, 2021
Changed - added feed search (#1402) Fixed - removed reference for deleted repair-steps (#1399) - Fix NotNullConstraintViolation when sharing news items with users (#1406) Signed-off-by: Benjamin Brahmer <[email protected]>
Grotax
added a commit
that referenced
this pull request
Jul 1, 2021
There are no additional changes compared to the latest beta. Changed - News now requires a 64bit OS - v2 API implementation (folder part) - Implemented sharing news items between nextcloud users (#1191) - Updated the news items table in DB to include sharer data (#1191) - Added route for sharing news items (#1191) - Added share data in news items serialization (#1191) - Added tests for the news items share feature (#1191) - Added sharing articles with nextcloud users (#1217) - Added sharing articles on social media (Facebook, Twitter) or mail (#1217) - Allow installation on Nextcloud v22 - Remove deprecated API endpoints and occ command (#935) - /api/v1-2/user - /api/v1-2/user/avatar - ./occ news:updater:all-feeds - added feed search (#1402) Fixed - allow calling `/items?getRead=false` without a feed/folder (#1380 #1356) - newestId does not return newest ID but last updated (#1339) - removed reference for deleted repair-steps (#1399) - Fix NotNullConstraintViolation when sharing news items with users (#1406) Signed-off-by: Benjamin Brahmer <[email protected]>
Merged
Grotax
added a commit
that referenced
this pull request
Jul 4, 2021
There are no additional changes compared to the latest beta. Changed - News now requires a 64bit OS - v2 API implementation (folder part) - Implemented sharing news items between nextcloud users (#1191) - Updated the news items table in DB to include sharer data (#1191) - Added route for sharing news items (#1191) - Added share data in news items serialization (#1191) - Added tests for the news items share feature (#1191) - Added sharing articles with nextcloud users (#1217) - Added sharing articles on social media (Facebook, Twitter) or mail (#1217) - Allow installation on Nextcloud v22 - Remove deprecated API endpoints and occ command (#935) - /api/v1-2/user - /api/v1-2/user/avatar - ./occ news:updater:all-feeds - added feed search (#1402) Fixed - allow calling `/items?getRead=false` without a feed/folder (#1380 #1356) - newestId does not return newest ID but last updated (#1339) - removed reference for deleted repair-steps (#1399) - Fix NotNullConstraintViolation when sharing news items with users (#1406) Signed-off-by: Benjamin Brahmer <[email protected]>
Neo11
pushed a commit
to Neo11/news
that referenced
this pull request
May 28, 2022
Changed - added feed search (nextcloud#1402) Fixed - removed reference for deleted repair-steps (nextcloud#1399) - Fix NotNullConstraintViolation when sharing news items with users (nextcloud#1406) Signed-off-by: Benjamin Brahmer <[email protected]>
Neo11
pushed a commit
to Neo11/news
that referenced
this pull request
May 28, 2022
There are no additional changes compared to the latest beta. Changed - News now requires a 64bit OS - v2 API implementation (folder part) - Implemented sharing news items between nextcloud users (nextcloud#1191) - Updated the news items table in DB to include sharer data (nextcloud#1191) - Added route for sharing news items (nextcloud#1191) - Added share data in news items serialization (nextcloud#1191) - Added tests for the news items share feature (nextcloud#1191) - Added sharing articles with nextcloud users (nextcloud#1217) - Added sharing articles on social media (Facebook, Twitter) or mail (nextcloud#1217) - Allow installation on Nextcloud v22 - Remove deprecated API endpoints and occ command (nextcloud#935) - /api/v1-2/user - /api/v1-2/user/avatar - ./occ news:updater:all-feeds - added feed search (nextcloud#1402) Fixed - allow calling `/items?getRead=false` without a feed/folder (nextcloud#1380 nextcloud#1356) - newestId does not return newest ID but last updated (nextcloud#1339) - removed reference for deleted repair-steps (nextcloud#1399) - Fix NotNullConstraintViolation when sharing news items with users (nextcloud#1406) Signed-off-by: Benjamin Brahmer <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #1375
Details for the maintainers/reviewers
Problem
When creating a copy of the item to be shared, we set the id to null. The goal of this was to allow the DBMS to automatically generate an id on insertion.
However, everytime an entities field changes, the field is marked as updated. In this case, it's the id field that gets marked as updated. Since Nextcloud has it's own code for persisting entities, it builds an SQL query with all of the updated fields. The result of this operation will be an SQL query explicitly setting the id to null - provoking an error (in some DBMS) since id is not nullable.
Solution
The solution is not to mark the id field as updated. As a consequence, the SQL query won't specifically set it to null on persist. The id will instead be generated automatically by the DBMS.
Implementation
duplicate()
function that creates a new item (with no id), and copies all of the fields. This will allow us to avoid writingsetId(null)
, and avoid playing around with updated fields. I didn't implement this because I wanted to stick with the current logic and reuse the clone function. However, personally, I like this solution. I wanted to hear your thoughts on this idea, and if it's your preferred method, I can do reimplement the solution that way.clone
function. This is the implemented solution in this pull request.Let me know what you think, thanks!