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

fix(entry): return None if the nested link is unresolvable #59

Merged
merged 2 commits into from Jul 16, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 3 additions & 1 deletion contentful/entry.py
Expand Up @@ -22,7 +22,9 @@ class Entry(FieldsResource):
"""

def _coerce(self, field_id, value, localized, includes, errors, resources=None):
if is_link(value) and not unresolvable(value, errors):
if is_link(value):
if unresolvable(value, errors):
return None
return self._build_nested_resource(
value,
localized,
Expand Down
58 changes: 58 additions & 0 deletions tests/entry_test.py
Expand Up @@ -42,6 +42,64 @@ def test_entry(self):
self.assertEqual(entry.name, 'foobar')
self.assertEqual(entry.date, '2016-06-06')

def test_entry_unresolved_link(self):
ContentTypeCache.__CACHE__ = []

errors = [
{
"sys": {
"id": "notResolvable",
"type": "error"
},
"details": {
"type": "Link",
"linkType": "Entry",
"id": "unresolvedLinkId"
}
}
]

entry = Entry(
{
'sys': {
'space': {
'sys': {
'type': 'Link',
'linkType': 'Space',
'id': 'foo'
}
},
'contentType': {
'sys': {
'type': 'Link',
'linkType': 'ContentType',
'id': 'foo'
}
},
'type': 'Entry',
'createdAt': '2016-06-06',
'updatedAt': '2016-06-06',
'deletedAt': '2016-06-06',
'id': 'foobar',
'version': 1
},
'fields': {
'name': 'foobar',
'entryLink': {
'sys': {
'type': 'Link',
'linkType': 'Entry',
'id': 'unresolvedLinkId'
}
}
}
},
None,
errors
)

self.assertEqual(entry.fields().get('entryLink'), None)

def test_cached_content_type_entry(self):
ContentTypeCache.__CACHE__ = []

Expand Down