mirror of
https://gitea.baerentsen.space/FrederikBaerentsen/BrickTracker.git
synced 2026-05-02 05:00:01 -05:00
fix(sets): adding sets now works after migration 20
This commit is contained in:
@@ -149,6 +149,14 @@ See [Migration Guide](docs/migration_guide.md) for detailed instructions
|
||||
- Corrected path resolution for data/instructions folder
|
||||
- Fixed instruction listing page to scan correct folder location
|
||||
- Fixed Peeron PDF creation to use correct data folder path
|
||||
- Fix foreign key constraint error when adding sets
|
||||
- Rebrickable set is now inserted before BrickTracker set to satisfy FK constraints
|
||||
- Resolves "FOREIGN KEY constraint failed" error when adding sets
|
||||
- Fix atomic transaction handling for set downloads
|
||||
- All database operations during set addition now use deferred execution
|
||||
- Ensures all-or-nothing behavior: if any part fails (set info, parts, minifigs), nothing is committed
|
||||
- Prevents partial set additions that would leave the database in an inconsistent state
|
||||
- Metadata updates (owners, tags) now defer until final commit
|
||||
|
||||
### 1.2.4
|
||||
|
||||
|
||||
@@ -191,19 +191,15 @@ class BrickMetadata(BrickRecord):
|
||||
parameters['set_id'] = brickset.fields.id
|
||||
parameters['state'] = state
|
||||
|
||||
rows, _ = BrickSQL().execute_and_commit(
|
||||
rows, _ = BrickSQL().execute(
|
||||
self.update_set_state_query,
|
||||
parameters=parameters,
|
||||
defer=True,
|
||||
name=self.as_column(),
|
||||
)
|
||||
|
||||
if rows != 1:
|
||||
raise DatabaseException('Could not update the {kind} "{name}" state for set {set} ({id})'.format( # noqa: E501
|
||||
kind=self.kind,
|
||||
name=self.fields.name,
|
||||
set=brickset.fields.set,
|
||||
id=brickset.fields.id,
|
||||
))
|
||||
# Note: rows will be -1 when deferred, so we can't validate here
|
||||
# Validation will happen at final commit in set.py
|
||||
|
||||
# Info
|
||||
logger.info('{kind} "{name}" state changed to "{state}" for set {set} ({id})'.format( # noqa: E501
|
||||
|
||||
+6
-4
@@ -59,6 +59,10 @@ class BrickSet(RebrickableSet):
|
||||
# Generate an UUID for self
|
||||
self.fields.id = str(uuid4())
|
||||
|
||||
# Insert the rebrickable set into database FIRST
|
||||
# This must happen before inserting bricktracker_sets due to FK constraint
|
||||
self.insert_rebrickable()
|
||||
|
||||
if not refresh:
|
||||
# Save the storage
|
||||
storage = BrickSetStorageList.get(
|
||||
@@ -74,7 +78,8 @@ class BrickSet(RebrickableSet):
|
||||
)
|
||||
self.fields.purchase_location = purchase_location.fields.id
|
||||
|
||||
# Insert into database
|
||||
# Insert into database (deferred - will execute at final commit)
|
||||
# All operations are atomic - if anything fails, nothing is committed
|
||||
self.insert(commit=False)
|
||||
|
||||
# Save the owners
|
||||
@@ -91,9 +96,6 @@ class BrickSet(RebrickableSet):
|
||||
tag = BrickSetTagList.get(id)
|
||||
tag.update_set_state(self, state=True)
|
||||
|
||||
# Insert the rebrickable set into database
|
||||
self.insert_rebrickable()
|
||||
|
||||
# Load the inventory
|
||||
if not BrickPartList.download(socket, self, refresh=refresh):
|
||||
return False
|
||||
|
||||
Reference in New Issue
Block a user