Compare commits

...

1 Commits

2 changed files with 21 additions and 11 deletions
+17 -7
View File
@@ -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
rows, _ = BrickSQL().execute_and_commit( if commit:
self.update_set_state_query, rows, _ = BrickSQL().execute_and_commit(
parameters=parameters, self.update_set_state_query,
name=self.as_column(), parameters=parameters,
) 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
View File
@@ -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):