forms: invalidate cache when adjusting transient formdata content (#31922)
This commit is contained in:
parent
18dcc53449
commit
47c250b3d1
|
@ -5796,6 +5796,9 @@ def test_field_live_comment_content(pub, http_requests):
|
|||
required=True, varname='bar'),
|
||||
fields.StringField(type='string', id='2', label='Baz', size='40'),
|
||||
fields.CommentField(id='5', label='bla {{form_var_bar}} bla', type='comment'),
|
||||
fields.StringField(type='string', id='6', label='Bar2', size='40',
|
||||
required=True, varname='bar2'),
|
||||
fields.CommentField(id='7', label='bla {{form_var_bar2}} bla', type='comment'),
|
||||
]
|
||||
formdef.store()
|
||||
formdef.data_class().wipe()
|
||||
|
@ -5813,6 +5816,16 @@ def test_field_live_comment_content(pub, http_requests):
|
|||
live_resp = app.post('/foo/live?modified_field_id=2', params=resp.form.submit_fields())
|
||||
assert live_resp.json['result']['5']['content'] == '<p>bla toto bla</p>'
|
||||
|
||||
# check evaluation of later fields
|
||||
# <https://dev.entrouvert.org/issues/31922>
|
||||
resp = app.get('/foo/')
|
||||
resp.form['f1'] = 'hello'
|
||||
live_resp = app.post('/foo/live', params=resp.form.submit_fields())
|
||||
assert live_resp.json['result']['5']['content'] == '<p>bla hello bla</p>'
|
||||
resp.form['f6'] = 'hello'
|
||||
live_resp = app.post('/foo/live', params=resp.form.submit_fields())
|
||||
assert live_resp.json['result']['7']['content'] == '<p>bla hello bla</p>'
|
||||
|
||||
def test_form_edit_and_backoffice_field_change(pub):
|
||||
create_user(pub)
|
||||
|
||||
|
|
|
@ -560,6 +560,10 @@ class FormDef(StorableObject):
|
|||
widget.field = field
|
||||
if transient_formdata and not widget.is_hidden:
|
||||
transient_formdata.data.update(self.get_field_data(field, widget))
|
||||
# invalidate cache as comment fields (and other things?) may
|
||||
# have accessed variables in non-lazy mode and caused a cache
|
||||
# with now-obsolete values.
|
||||
get_publisher().substitutions.invalidate_cache()
|
||||
widget._parsed = False
|
||||
widget.error = None
|
||||
|
||||
|
|
Loading…
Reference in New Issue