Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 90f5a5b240 |
@@ -182,7 +182,8 @@ class BrickMetadata(BrickRecord):
|
|||||||
/,
|
/,
|
||||||
*,
|
*,
|
||||||
json: Any | None = None,
|
json: Any | None = None,
|
||||||
state: Any | None = None
|
state: Any | None = None,
|
||||||
|
commit: bool = True
|
||||||
) -> Any:
|
) -> Any:
|
||||||
if state is None and json is not None:
|
if state is None and json is not None:
|
||||||
state = json.get('value', False)
|
state = json.get('value', False)
|
||||||
@@ -191,13 +192,22 @@ class BrickMetadata(BrickRecord):
|
|||||||
parameters['set_id'] = brickset.fields.id
|
parameters['set_id'] = brickset.fields.id
|
||||||
parameters['state'] = state
|
parameters['state'] = state
|
||||||
|
|
||||||
|
if commit:
|
||||||
rows, _ = BrickSQL().execute_and_commit(
|
rows, _ = BrickSQL().execute_and_commit(
|
||||||
self.update_set_state_query,
|
self.update_set_state_query,
|
||||||
parameters=parameters,
|
parameters=parameters,
|
||||||
name=self.as_column(),
|
name=self.as_column(),
|
||||||
)
|
)
|
||||||
|
else:
|
||||||
|
rows, _ = BrickSQL().execute(
|
||||||
|
self.update_set_state_query,
|
||||||
|
parameters=parameters,
|
||||||
|
defer=True,
|
||||||
|
name=self.as_column(),
|
||||||
|
)
|
||||||
|
|
||||||
if rows != 1:
|
# When deferred, rows will be -1, so skip the check
|
||||||
|
if commit and rows != 1:
|
||||||
raise DatabaseException('Could not update the {kind} state for set {set} ({id})'.format(
|
raise DatabaseException('Could not update the {kind} state for set {set} ({id})'.format(
|
||||||
kind=self.kind,
|
kind=self.kind,
|
||||||
set=brickset.fields.set,
|
set=brickset.fields.set,
|
||||||
|
|||||||
+4
-4
@@ -82,19 +82,19 @@ class BrickSet(RebrickableSet):
|
|||||||
# All operations are atomic - if anything fails, nothing is committed
|
# All operations are atomic - if anything fails, nothing is committed
|
||||||
self.insert(commit=False)
|
self.insert(commit=False)
|
||||||
|
|
||||||
# Save the owners
|
# Save the owners (deferred - will execute at final commit)
|
||||||
owners: list[str] = list(data.get('owners', []))
|
owners: list[str] = list(data.get('owners', []))
|
||||||
|
|
||||||
for id in owners:
|
for id in owners:
|
||||||
owner = BrickSetOwnerList.get(id)
|
owner = BrickSetOwnerList.get(id)
|
||||||
owner.update_set_state(self, state=True)
|
owner.update_set_state(self, state=True, commit=False)
|
||||||
|
|
||||||
# Save the tags
|
# Save the tags (deferred - will execute at final commit)
|
||||||
tags: list[str] = list(data.get('tags', []))
|
tags: list[str] = list(data.get('tags', []))
|
||||||
|
|
||||||
for id in tags:
|
for id in tags:
|
||||||
tag = BrickSetTagList.get(id)
|
tag = BrickSetTagList.get(id)
|
||||||
tag.update_set_state(self, state=True)
|
tag.update_set_state(self, state=True, commit=False)
|
||||||
|
|
||||||
# Load the inventory
|
# Load the inventory
|
||||||
if not BrickPartList.download(socket, self, refresh=refresh):
|
if not BrickPartList.download(socket, self, refresh=refresh):
|
||||||
|
|||||||
Reference in New Issue
Block a user