Skip to content

Commit 35a6b7b

Browse files
chenkasirergonzalocasas
authored andcommitted
fixed graph serialization in assembly
1 parent 247a460 commit 35a6b7b

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1919
* Fixed `area_polygon` that was, in some cases, returning a negative area
2020
* Fixed support for `System.Decimal` data type on json serialization.
2121
* Fixed `AttributeError` in Plotter's `PolylineArtist` and `SegementArtist`.
22+
* Fixed wrong key type when de-serializing `Graph` with integer keys leading to node not found.
2223

2324
### Removed
2425

src/compas/datastructures/assembly/assembly.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,14 @@ def JSONSCHEMANAME(self):
5858
def data(self):
5959
data = {
6060
"attributes": self.attributes,
61-
"graph": self.graph.data,
61+
"graph": self.graph,
6262
}
6363
return data
6464

6565
@data.setter
6666
def data(self, data):
6767
self.attributes.update(data["attributes"] or {})
68-
self.graph.data = data["graph"]
68+
self.graph = data["graph"]
6969
self._parts = {part.guid: part.key for part in self.parts()}
7070

7171
# ==========================================================================

tests/compas/datastructures/test_assembly.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import pytest
22

3+
from compas.data import json_dumps
4+
from compas.data import json_loads
35
from compas.datastructures import Assembly
46
from compas.datastructures import AssemblyError
57
from compas.datastructures import Part
@@ -69,9 +71,22 @@ def test_find_by_key():
6971
assert assembly.find_by_key("100") is None
7072

7173

72-
def test_find_by_key_after_deserialization():
74+
def test_find_by_key_after_from_data():
7375
assembly = Assembly()
7476
part = Part()
7577
assembly.add_part(part, key=2)
7678
assembly = Assembly.from_data(assembly.to_data())
7779
assert assembly.find_by_key(2) == part
80+
81+
82+
def test_find_by_key_after_deserialization():
83+
assembly = Assembly()
84+
part = Part(name="test_part")
85+
assembly.add_part(part, key=2)
86+
assembly = json_loads(json_dumps(assembly))
87+
88+
deserialized_part = assembly.find_by_key(2)
89+
assert deserialized_part.name == part.name
90+
assert deserialized_part.key == part.key
91+
assert deserialized_part.guid == part.guid
92+
assert deserialized_part.attributes == part.attributes

0 commit comments

Comments
 (0)