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

Sometimes Asset.url() return empty string #69

Closed mark-mishyn closed 2 years ago

mark-mishyn commented 2 years ago

Sometimes (I cannot detect the conditions) asset-field in Entry have no attached file, so asset.utl() return empty string.

For example

import contentful

client = contentful.Client(
     Config.CONTENTFUL_SPACE_ID,
     Config.CONTENTFUL_PREVIEW_ACCESS_TOKEN,
     api_url="preview.contentful.com")

# first approach  
entry = client.entry('xyz', {'locale': '*'})
asset = entry.fields('en')['some_image']  # here asset is <Asset id='xyz' url=''>
asset.url()  # this one returns empty string

but if I create the same asset directly, .url() works fine

# second approach  
client.asset('xyz')  # here asset is <Asset id='xyz' url='//images.ctfassets.net/...'>

First approach definitely worked before and it works now (at least sometimes), so I really cannot understand what is going on.

UPD: The reason was that we renamed default locale en-US > en and after that entries which were requested with locale="*" had empty Assets. So we had to pass our new default locale to the Client class.