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

TypeError: 'Link' object is not subscriptable #41

Closed
AngusP opened this issue Nov 20, 2018 · 2 comments
Closed

TypeError: 'Link' object is not subscriptable #41

AngusP opened this issue Nov 20, 2018 · 2 comments

Comments

@AngusP
Copy link

AngusP commented Nov 20, 2018

Contentful 1.11.3 on Python 3.6.6 throwing TypeError when trying to answer the following call:

client.entries({'content_type': 'blogPost'})

The content model is roughly this:

blogPost
  - title : short text
  - slug : short text
  - hero_image : media
  - description : long text
  - body : references, many, accept only 'blogPostLayout'
  - author : reference, accept only 'person'
  - tags : short text, list
  - publish date : datetime
  - external comments id : number, unique

blogPostLayout
  - slug : short text, unique
  - main body : rich text, allow linking other entries, allow only 'blogPostLayout', 'blogPostMarkdown'

blogPostMarkdown
  - content : long text, format Markdown

blogPostRichContent
  - content : rich text, allow linking inline entries

This issue was caused by a blogPost that had in its body references to the same blogPostLayout twice, and additionally one other blogPostLayout. These blogPostLayouts themselves contained only an embedded entry to one blogPostMarkdown each.

The issue would clear after removing the second reference to the same blogPostLayout

I can provide further details if you need, and am happy to be contacted by Contentful support directly.
I'm not sure if the library includes a way to dump the schema?

My best guess for the cause is that the client library is trying to populate something it has already 'hydrated' (if I understand the nomenclature)

Full traceback:

content_client.entries({'content_type': 'blogPost'})

~/web/VENV/lib64/python3.6/site-packages/contentful/client.py in entries(self, query)
    254         return self._get(
    255             self.environment_url('/entries'),
--> 256             query
    257         )
    258 

~/web/VENV/lib64/python3.6/site-packages/contentful/client.py in _get(self, url, query)
    573             response.json(),
    574             max_depth=self.max_include_resolution_depth,
--> 575             reuse_entries=self.reuse_entries
    576         ).build()
    577 

~/web/VENV/lib64/python3.6/site-packages/contentful/resource_builder.py in build(self)
     59                     localized=True
     60                 )
---> 61             return self._build_array()
     62         return self._build_single()
     63 

~/web/VENV/lib64/python3.6/site-packages/contentful/resource_builder.py in _build_array(self)
     84                     includes=includes,
     85                     errors=errors
---> 86                  ) for item in self.json['items']
     87                  if not unresolvable(item, self._errors())]
     88 

~/web/VENV/lib64/python3.6/site-packages/contentful/resource_builder.py in <listcomp>(.0)
     85                     errors=errors
     86                  ) for item in self.json['items']
---> 87                  if not unresolvable(item, self._errors())]
     88 
     89         return Array(self.json, items)

~/web/VENV/lib64/python3.6/site-packages/contentful/resource_builder.py in _build_item(self, item, includes, errors)
    118                 resources=self.resources,
    119                 depth=self.depth,
--> 120                 max_depth=self.max_depth
    121             )
    122 

~/web/VENV/lib64/python3.6/site-packages/contentful/resource.py in __init__(self, item, includes, errors, localized, resources, **kwargs)
    102         )
    103 
--> 104         self._fields = self._hydrate_fields(item, localized, includes, errors, resources=resources)
    105 
    106     def _hydrate_fields(self, item, localized, includes, errors, resources=None):

~/web/VENV/lib64/python3.6/site-packages/contentful/resource.py in _hydrate_fields(self, item, localized, includes, errors, resources)
    119             self._hydrate_localized_entry(fields, item, includes, errors, resources)
    120         else:
--> 121             self._hydrate_non_localized_entry(fields, item, includes, errors, resources)
    122         return fields
    123 

~/web/VENV/lib64/python3.6/site-packages/contentful/resource.py in _hydrate_non_localized_entry(self, fields, item, includes, errors, resources)
    144                 includes,
    145                 errors,
--> 146                 resources=resources
    147             )
    148 

~/web/VENV/lib64/python3.6/site-packages/contentful/entry.py in _coerce(self, field_id, value, localized, includes, errors, resources)
     42                         includes,
     43                         errors,
---> 44                         resources=resources
     45                     )
     46                 )

~/web/VENV/lib64/python3.6/site-packages/contentful/entry.py in _build_nested_resource(self, value, localized, includes, errors, resources)
     97                     includes,
     98                     errors,
---> 99                     resources=resources
    100                 )
    101 

~/web/VENV/lib64/python3.6/site-packages/contentful/entry.py in _resolve_include(self, resource, localized, includes, errors, resources)
    113             resources=resources,
    114             depth=self._depth + 1,
--> 115             max_depth=self._max_depth
    116         ).build()
    117 

~/web/VENV/lib64/python3.6/site-packages/contentful/resource_builder.py in build(self)
     60                 )
     61             return self._build_array()
---> 62         return self._build_single()
     63 
     64     def _build_single(self):

~/web/VENV/lib64/python3.6/site-packages/contentful/resource_builder.py in _build_single(self)
     73             self.json,
     74             includes=includes,
---> 75             errors=errors
     76         )
     77 

~/web/VENV/lib64/python3.6/site-packages/contentful/resource_builder.py in _build_item(self, item, includes, errors)
    118                 resources=self.resources,
    119                 depth=self.depth,
--> 120                 max_depth=self.max_depth
    121             )
    122 

~/web/VENV/lib64/python3.6/site-packages/contentful/resource.py in __init__(self, item, includes, errors, localized, resources, **kwargs)
    102         )
    103 
--> 104         self._fields = self._hydrate_fields(item, localized, includes, errors, resources=resources)
    105 
    106     def _hydrate_fields(self, item, localized, includes, errors, resources=None):

~/web/VENV/lib64/python3.6/site-packages/contentful/resource.py in _hydrate_fields(self, item, localized, includes, errors, resources)
    119             self._hydrate_localized_entry(fields, item, includes, errors, resources)
    120         else:
--> 121             self._hydrate_non_localized_entry(fields, item, includes, errors, resources)
    122         return fields
    123 

~/web/VENV/lib64/python3.6/site-packages/contentful/resource.py in _hydrate_non_localized_entry(self, fields, item, includes, errors, resources)
    144                 includes,
    145                 errors,
--> 146                 resources=resources
    147             )
    148 

~/web/VENV/lib64/python3.6/site-packages/contentful/entry.py in _coerce(self, field_id, value, localized, includes, errors, resources)
     60                     resources=resources,
     61                     default_locale=self.default_locale,
---> 62                     locale=self.sys.get('locale', '*')
     63                 )
     64 

~/web/VENV/lib64/python3.6/site-packages/contentful/content_type_field.py in coerce(self, value, **kwargs)
     37         if value is None:
     38             return None
---> 39         return self._coercion.coerce(value, **kwargs)
     40 
     41     def _get_coercion(self):

~/web/VENV/lib64/python3.6/site-packages/contentful/content_type_field_types.py in coerce(self, value, includes, errors, resources, default_locale, locale)
    233             resources=resources,
    234             default_locale=default_locale,
--> 235             locale=locale
    236         )

~/web/VENV/lib64/python3.6/site-packages/contentful/content_type_field_types.py in _coerce_block(self, value, includes, errors, resources, default_locale, locale)
    195                     resources=resources,
    196                     default_locale=default_locale,
--> 197                     locale=locale
    198                 )
    199                 if link:

~/web/VENV/lib64/python3.6/site-packages/contentful/content_type_field_types.py in _coerce_link(self, value, includes, errors, resources, default_locale, locale)
    151 
    152     def _coerce_link(self, value, includes=None, errors=None, resources=None, default_locale='en-US', locale=None):
--> 153         if value['data']['target']['sys']['type'] != 'Link':
    154             return value['data']['target']
    155 

TypeError: 'Link' object is not subscriptable
@dlitvakb
Copy link
Contributor

Hey @AngusP ,

Could you please create a support request on https://support.contentful.com and ask for me, please include Space ID and Delivery Access Token, so that I can take a look at what the issue may be.

Cheers

@AngusP
Copy link
Author

AngusP commented Nov 20, 2018

@dlitvakb will do, cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants