diff --git a/CHANGELOG.md b/CHANGELOG.md
index 783a5b7..d6fd2cb 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,7 @@
### Fixed
* Fix getting sender from a combination of legacy Diaspora encrypted payload and new entity names (for example `author`). This combination probably only existed in this library.
+* Correctly extend entity `_children`. Certain Diaspora payloads caused `_children` for an entity to be written over by an empty list, causing for example status message photos to not be saved. Correctly do an extend on it.
### Removed
* `Post.photos` entity attribute was never used by any code and has been removed. Child entities of type `Image` are stored in the `Post._children` as before.
diff --git a/federation/entities/diaspora/mappers.py b/federation/entities/diaspora/mappers.py
index 58a0439..29f6790 100644
--- a/federation/entities/diaspora/mappers.py
+++ b/federation/entities/diaspora/mappers.py
@@ -99,7 +99,7 @@ def element_to_objects(element, sender_key_fetcher=None, user=None):
return []
# Do child elements
for child in element:
- entity._children = element_to_objects(child)
+ entity._children.extend(element_to_objects(child))
# Add to entities list
entities.append(entity)
if cls == DiasporaRequest:
diff --git a/federation/tests/entities/diaspora/test_mappers.py b/federation/tests/entities/diaspora/test_mappers.py
index 207a9f8..9732b4d 100644
--- a/federation/tests/entities/diaspora/test_mappers.py
+++ b/federation/tests/entities/diaspora/test_mappers.py
@@ -15,7 +15,7 @@ from federation.tests.fixtures.payloads import (
DIASPORA_POST_SIMPLE, DIASPORA_POST_COMMENT, DIASPORA_POST_LIKE,
DIASPORA_REQUEST, DIASPORA_PROFILE, DIASPORA_POST_INVALID, DIASPORA_RETRACTION,
DIASPORA_POST_WITH_PHOTOS, DIASPORA_POST_LEGACY_TIMESTAMP, DIASPORA_POST_LEGACY, DIASPORA_CONTACT,
- DIASPORA_LEGACY_REQUEST_RETRACTION)
+ DIASPORA_LEGACY_REQUEST_RETRACTION, DIASPORA_POST_WITH_PHOTOS_2)
def mock_fill(attributes):
@@ -75,6 +75,13 @@ class TestDiasporaEntityMappersReceive():
assert photo.public == False
assert photo.created_at == datetime(2011, 7, 20, 1, 36, 7)
+ entities = message_to_objects(DIASPORA_POST_WITH_PHOTOS_2)
+ assert len(entities) == 1
+ post = entities[0]
+ assert isinstance(post, DiasporaPost)
+ photo = post._children[0]
+ assert isinstance(photo, Image)
+
@patch("federation.entities.diaspora.mappers.DiasporaComment._validate_signatures")
def test_message_to_objects_comment(self, mock_validate):
entities = message_to_objects(DIASPORA_POST_COMMENT, sender_key_fetcher=Mock())
diff --git a/federation/tests/fixtures/payloads.py b/federation/tests/fixtures/payloads.py
index 5d3c141..739ea7a 100644
--- a/federation/tests/fixtures/payloads.py
+++ b/federation/tests/fixtures/payloads.py
@@ -109,6 +109,30 @@ DIASPORA_POST_WITH_PHOTOS = """
"""
+DIASPORA_POST_WITH_PHOTOS_2 = """
+
+ xxxxxxxxxxxxxxx@diasp.org
+ fewhefihefifhwihfwehfwehfiuwehfiuwhif
+ 2017-06-10T14:41:47Z
+ mobile
+ #foo #bar (fewfefewfwfewfwe)
+
+ fjwjewiofjoiwjfiowefewew
+ xxxxxxxxxxxxxxxxx@diasp.org
+ true
+ 2017-06-10T14:41:28Z
+ https://diasp.org/uploads/images/
+ fewhuwehiufhuiefhuiwee.jpg
+
+ fewhefihefifhwihfwehfwehfiuwehfiuwhif
+ 4032
+ 3024
+
+ true
+
+"""
+
+
DIASPORA_POST_INVALID = """
((status message))