Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed an IndexError: list assignment index out of range error in RichTextField coersion #52

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion contentful/content_type_field_types.py
Expand Up @@ -217,7 +217,7 @@ def _coerce_block(self, value, includes=None, errors=None, resources=None, defau
for node_index, coerced_node in coerced_nodes.items():
value['content'][node_index] = coerced_node

for node_index in invalid_nodes:
for node_index in reversed(invalid_nodes):
del value['content'][node_index]

return value
Expand Down
38 changes: 38 additions & 0 deletions tests/content_type_field_types_test.py
Expand Up @@ -203,3 +203,41 @@ def test_rich_text_field(self):

coerced = rt_field.coerce(document)
self.assertTrue(isinstance(coerced['content'][0]['data']['target'], Link))

# with 2 embedded entries that have errors, both will be removed
# without a list index out of range error
document = {
"nodeType": "document",
"content": [{
"nodeType": "embedded-entry-block",
"nodeClass": "block",
"data": {
"target": {
"sys": {
"type": "Link",
"linkType": "Entry",
"id": "4JJ21pcEI0QSsea20g6K6K"
}
}
}
}, {
"nodeType": "embedded-entry-block",
"nodeClass": "block",
"data": {
"target": {
"sys": {
"type": "Link",
"linkType": "Entry",
"id": "4JJ21pcEI0QSsea20g6K6K"
}
}
}
}]
}

errors = [{"details": {"id": "4JJ21pcEI0QSsea20g6K6K"}}]

self.assertEqual(rt_field.coerce(document, errors=errors), {
"nodeType": "document",
"content": []
})