contentful / contentful.rb

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

Content type caching breaks for multiple clients with same content type names #253

Closed EricNelson12 closed 2 years ago

EricNelson12 commented 2 years ago

Since ContentTypeCache has a static field __CACHE__ = [], this __CACHE__ object is reused across clients.

ContentTypeCache's methods get and update_cache are called statically instead of on different instances of ContentTypeCache

So if I have two spaces, and need two clients like

client_for_space_1 = contentful.Client(<credentials>...,space_id = 1)
client_for_space_2 = contentful.Client(<credentials>..., space_id = 2)

When update_cache is called for the second client, it will replace the cache made by the first client.

This might go undetected if the spaces have difference content type ids or content types with different field names. But if the spaces have the same content type ids, then when the cache is called like:

content_type = ContentTypeCache.get(
            self.sys['content_type'].id
        )

It will happily return a content type which might not have the same field type. This causes errors if for example, it expects a dict, but instead gets a string type.

So either new instances of ContentTypeCache should be created per client, or the key to __CACHE__ should be prefixed with the space id.

Thanks for reading!

EricNelson12 commented 2 years ago

Accidentally created this for ruby instead of python. See https://github.com/contentful/contentful.py/issues/74 for the story of how I was tricked by a button :laughing:

And link to the python version of this issue:

https://github.com/contentful/contentful.py/issues/73