clear collection titles before updating#280
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #280 +/- ##
==========================================
+ Coverage 81.28% 81.37% +0.09%
==========================================
Files 55 55
Lines 2362 2363 +1
Branches 236 236
==========================================
+ Hits 1920 1923 +3
+ Misses 381 380 -1
+ Partials 61 60 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
@benoit74 , I am wondering if this is not a good time to add a unique constraint to the collectiontitle table too. The keys for the constraint will be title_id, collection_id, and path. WDYT? |
We already have a unique constraint (primary key actually) on |
No, we don't and we shouldn't because it acts as a many-to-many intermediary table for collection and title. But having a unique constraint made of |
|
But since |
Yup, indeed. Just realized they are both used as primary keys. Sorry, my bad. |
7f495bd to
c302d9b
Compare
Rationale
This PR clears the collection titles before creating the new ones to be used for an update. By clearing the old collection titles in memory, we avoid creating duplicate collection titles when the original collection title is sent in the update reqeust. This is because SQLAlchemy list of collection titles isn't cleared with just
session.delete.As a consequence, having duplicate collection titles leads to creating duplicate book locations which violates location unique constraint.
Changes
This fixes #277