contentful / contentful.py

Python client for the Contentful Content Delivery API https://www.contentful.com/developers/documentation/content-delivery-api/
MIT License
45 stars 39 forks source link

maximum recursion depth exceeded issue when trying to retrieve entries #61

Closed tripzone closed 2 years ago

tripzone commented 4 years ago

Hi we're using the python SDK and trying to retrieve list of entries of a specific type using this method

data = client.entries({"content_type": 'video'})

there are around 150 contents of this type and we're getting the following error

File "/Users/mesadat/Documents/content-recommender/venv/lib/python3.7/site-packages/contentful/resource.py", line 54, in _hydrate_sys for k, v in item.get('sys', {}).items(): RecursionError: maximum recursion depth exceeded while calling a Python object

we are using the same method on other content types without an issue, they don't have as many entries so we're suspecting maybe the large number of content may be causing this error

afraazali commented 3 years ago

We're facing the same issue. For us it's caused by cyclic references. So if have 2 pieces of content, A and B. A refers to B either via a reference field or an embed and then B refers to A either through a reference field or inline embed.

wgins commented 3 years ago

I believe limiting recursion depth should solve this issue:

max_include_resolution_depth=5

https://github.com/contentful/contentful.py#configuration

afraazali commented 3 years ago

Unfortunately I got the same error. I also use the include filter in the query. I figure that would make a difference as well. The content we have setup does have a several references.

rubydog commented 2 years ago

Hey @afraazali,

Which version of the SDK are you using? If using master, please update to the latest version of master, and reduce the client configuration parameter max_include_resolution_depth to a value equal or greater than your maximum include level. This will avoid resolving circular references for a long time and running into maximum recursion depth.

Please let me know if this helps,

Cheers

rubydog commented 2 years ago

Hey @afraazali, @kasrazahir did the above comment help?

moreindirection commented 2 years ago

I'm having the same problem with 1.13.1.

client.entries({'limit': 1})

results in RecursionError: maximum recursion depth exceeded while calling a Python object

I tried using the max_include_resolution_depth parameter, as suggested above, but it's rejected by the server:

client.entries({'limit': 1, 'include': 1, 'max_include_resolution_depth': 1})

returns:

BadRequestError: HTTP status code: 400
Message: The query you sent was invalid. Probably a filter or ordering specification is not applicable to the type of a field.
Details: The path "max_include_resolution_depth" is not recognized
99littlebugs commented 2 years ago

max_include_resolution_depth is an optional parameter on client initialization, not entry retrieval. example: contetnful.Client(...,max_include_resolution_depth=XX)

99littlebugs commented 2 years ago

I am also having this issue even with 1 include. I set reuse_entries to True in the client configuration and that seemed to help. I am on the latest version - 1.13.1

tjtripp commented 2 years ago

99littlebugs commented: I am also having this issue even with 1 include. I set reuse_entries to True in the client configuration and that seemed to help. I am on the latest version - 1.13.1

Limiting depth didn't help me either. So instead, I took this approach (reuse_entries) as well and it solved my problem.

rubydog commented 2 years ago

@tjtripp can you please share your client initialisation and entries retrieval code?

tjtripp commented 2 years ago

@rubydog - Sure - it's pretty much straight from the examples. I added the resue_entries parameter and that fixed the max recursion error. Now my queries work. Then I added the timeout_s and max_rate_limit_retries parameters to solve a rate limit issue.

client = contentful.Client(
    space_id,  
    api_key,  
    reuse_entries=True,  
    timeout_s=5,
    max_rate_limit_retries=3
)

entry = client.entry(entry_id)
rubydog commented 2 years ago

So does it work then with resue_entries param?

tjtripp commented 2 years ago

Yes, it works - I'll edit my comments to state that it works. Thanks!

Psychotechnopath commented 1 year ago

For me the issue persists, even with

max_include_resolution_depth=0, reuse_entries=True,

in Contentfull class initialization

and include=1 as query parameter :(