data_sources: return an empty list for an unknown carddef (#42960)

This commit is contained in:
Thomas NOËL 2020-05-15 16:02:56 +02:00
parent 5f8c3e5685
commit 2f6e7a3597
2 changed files with 15 additions and 1 deletions

View File

@ -5848,6 +5848,17 @@ def test_studio_card_item_link(pub, studio):
resp = resp.click('card plop')
assert '<div class="value">plop</div>' in resp
# link to a unknown carddef
carddef2.fields = [
fields.ItemField(id='1', label='Test', type='item',
data_source={'type': 'carddef:unknown', 'value': ''}),
]
carddef2.store()
app = login(get_app(pub))
resp = app.get('/backoffice/data/')
resp = resp.click('bar')
resp = resp.click('Add') # no error
# look without access rights
carddef.backoffice_submission_roles = None
carddef.workflow_roles = {'_editor': None}

View File

@ -149,7 +149,10 @@ def get_structured_items(data_source, mode=None):
if data_source.get('type') and data_source.get('type').startswith('carddef:'):
# cards
from wcs.carddef import CardDef
carddef = CardDef.get_by_urlname(data_source['type'][8:])
try:
carddef = CardDef.get_by_urlname(data_source['type'][8:])
except KeyError:
return []
items = [x.get_data_source_structured_item()
for x in carddef.data_class().select()
if not x.is_draft()]