misc: don't advertise _live_ variables if card is missing (#45296)
This commit is contained in:
parent
62092e89e7
commit
3ca2d56840
|
@ -814,6 +814,8 @@ def test_lazy_formdata_live_item(pub):
|
|||
formdata.data = {
|
||||
'0': str(carddata.id),
|
||||
}
|
||||
formdata.data['0_display'] = formdef.fields[0].store_display_value(formdata.data, '0')
|
||||
formdata.data['0_structured'] = formdef.fields[0].store_structured_value(formdata.data, '0')
|
||||
pub.substitutions.feed(pub)
|
||||
pub.substitutions.feed(formdef)
|
||||
pub.substitutions.feed(formdata)
|
||||
|
@ -823,11 +825,13 @@ def test_lazy_formdata_live_item(pub):
|
|||
assert context['form_var_foo_live_number'] == carddata.get_display_id()
|
||||
assert context['form_var_foo_live_var_name'] == 'baz'
|
||||
assert context['form_var_foo_live_var_attr'] == 'attr2'
|
||||
assert 'form_var_foo_live_var_attr' in context.get_flat_keys()
|
||||
|
||||
CardDef.wipe()
|
||||
context = pub.substitutions.get_context_variables(mode='lazy')
|
||||
with pytest.raises(KeyError):
|
||||
context['form_var_foo_live_name']
|
||||
assert 'form_var_foo_live_var_attr' not in context.get_flat_keys()
|
||||
|
||||
|
||||
def test_lazy_formdata_queryset(pub, variable_test_data):
|
||||
|
|
|
@ -651,7 +651,13 @@ class LazyFieldVarStructured(LazyFieldVar):
|
|||
|
||||
keys = ['raw', 'structured']
|
||||
if self._field.data_source and self._field.data_source.get('type', '').startswith('carddef:'):
|
||||
keys.append('live')
|
||||
try:
|
||||
self.live
|
||||
except AttributeError:
|
||||
# don't advertise "live" if linked data is missing
|
||||
pass
|
||||
else:
|
||||
keys.append('live')
|
||||
|
||||
def walk(base, value):
|
||||
if isinstance(value, dict):
|
||||
|
|
Loading…
Reference in New Issue