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: NotNullConstraintViolation when sharing with users #1406

Merged
merged 2 commits into from
Jun 16, 2021

Conversation

mnassabain
Copy link
Contributor

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

  1. First idea: Implement a duplicate() function that creates a new item (with no id), and copies all of the fields. This will allow us to avoid writing setId(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.
  2. Second idea: Modify the clone function to set the id to NULL. This is done to set the id to null BEFORE resetting the updated fields. Also a pretty good solution, as it allows us to use the clone function. This is the implemented solution in this pull request.

Let me know what you think, thanks!

@codecov-commenter
Copy link

codecov-commenter commented Jun 12, 2021

Codecov Report

Merging #1406 (07d37d1) into master (9410228) will increase coverage by 0.01%.
The diff coverage is 100.00%.

Impacted file tree graph

@@             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     
Impacted Files Coverage Δ
lib/Service/ShareService.php 100.00% <ø> (ø)
lib/Db/Item.php 100.00% <100.00%> (ø)
lib/Service/FeedServiceV2.php 100.00% <0.00%> (ø)
lib/Command/Debug/ItemList.php 100.00% <0.00%> (ø)
lib/Command/Debug/FeedItemList.php 100.00% <0.00%> (ø)
lib/Command/Debug/FolderItemList.php 100.00% <0.00%> (ø)
lib/Fetcher/FeedFetcher.php 89.11% <0.00%> (+0.44%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9410228...07d37d1. Read the comment docs.

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]>
@Grotax Grotax merged commit be45dd9 into nextcloud:master Jun 16, 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]>
@Grotax Grotax mentioned this pull request Jun 16, 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]>
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]>
@Grotax Grotax mentioned this pull request Jul 1, 2021
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
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NotNullConstraintViolation when Sharing to User
4 participants