From c7c3d2806ff39bb1a4b3442b1ba256a541f14144 Mon Sep 17 00:00:00 2001 From: Darragh Van Tichelen Date: Sun, 19 Jan 2025 19:21:10 +0100 Subject: [PATCH 1/2] Fix server delete composite handling --- CHANGELOG.md | 2 ++ server/src/api/socket/shape/__init__.py | 21 ++++++++++++++++----- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8a60b54cd..9af0f8186 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -101,6 +101,8 @@ tech changes will usually be stripped from release notes for the public - Input changes could not persist or save on the wrong shape if selection focus was changed while editing (see selection changes) - Modals - Dragging modals (e.g. notes) now also brings them to the foreground as if clicked +- Composites: + - Moving composites to a different location could sometimes lead to errors on the client even though the moves were succesful serverside ## [2024.3.1] - 2024-11-12 diff --git a/server/src/api/socket/shape/__init__.py b/server/src/api/socket/shape/__init__.py index 5735833ef..ed5e8d4fc 100644 --- a/server/src/api/socket/shape/__init__.py +++ b/server/src/api/socket/shape/__init__.py @@ -151,11 +151,11 @@ def _get_shapes_from_uuids( uuids: list[str], filter_layer: bool ) -> SelectSequence[Shape]: query = Shape.select().where( - (Shape.uuid << uuids) # pyright: ignore[reportGeneralTypeIssues] + (Shape.uuid << uuids) # type: ignore ) if filter_layer: query = query.where( - ~(Shape.layer >> None) # pyright: ignore[reportGeneralTypeIssues] + ~(Shape.layer >> None) # type: ignore ) return query @@ -407,14 +407,19 @@ async def move_shapes(sid: str, raw_data: Any): if data.target.layer: target_layer = floor.layers.where(Layer.name == data.target.layer)[0] + shape_uuids = set() shapes = [] old_floor = None for shape in _get_shapes_from_uuids(data.shapes, False): + if shape.uuid in shape_uuids: + continue + # toggle composite patch parent = None if shape.composite_parent: parent = shape.composite_parent[0].parent shape = Shape.get_by_id(parent.subtype.active_variant) + print(f"Parent found for {shape.uuid}") layer = target_layer if shape.layer: @@ -425,13 +430,19 @@ async def move_shapes(sid: str, raw_data: Any): logger.warn("Attempt to move a shape without layer info") continue - shapes.append((shape, layer)) + # Shape can be different from the one checked at the start of the loop + if shape.uuid not in shape_uuids: + shape_uuids.add(shape.uuid) + shapes.append((shape, layer)) if parent: - shapes.append((parent, layer)) + if parent.uuid not in shape_uuids: + shape_uuids.add(parent.uuid) + shapes.append((parent, layer)) for csa in parent.shape_variants: variant = csa.variant - if variant != shape: + if variant != shape and variant.uuid not in shape_uuids: + shape_uuids.add(variant.uuid) shapes.append((variant, layer)) if old_floor: From 174ab0191141768225cf59ec9bd480fa9ef261d5 Mon Sep 17 00:00:00 2001 From: Darragh Van Tichelen Date: Sun, 19 Jan 2025 19:32:41 +0100 Subject: [PATCH 2/2] Fix formatting --- server/src/api/socket/shape/__init__.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/server/src/api/socket/shape/__init__.py b/server/src/api/socket/shape/__init__.py index ed5e8d4fc..a56d85deb 100644 --- a/server/src/api/socket/shape/__init__.py +++ b/server/src/api/socket/shape/__init__.py @@ -150,13 +150,9 @@ async def send_remove_shapes( def _get_shapes_from_uuids( uuids: list[str], filter_layer: bool ) -> SelectSequence[Shape]: - query = Shape.select().where( - (Shape.uuid << uuids) # type: ignore - ) + query = Shape.select().where((Shape.uuid << uuids)) # type: ignore if filter_layer: - query = query.where( - ~(Shape.layer >> None) # type: ignore - ) + query = query.where(~(Shape.layer >> None)) # type: ignore return query