My rule executes "After saving new content". My View returns existing content related to the newly-created content by a common field ("Legacy ID"). I can preview the View results entering the contextual filter values that Views Loop should be providing to the view, and the view returns the correct existing content each time. The view itself does not have caching enabled.
The data is correct when adding individual nodes.
However when multiple nodes are created at once (use case: importing >1 nodes with feeds), it appears that Views Loop does not refresh the view results for each node/rule execution. The result is that the Views Loop always returns the data from the first rule execution, even though the view should be passed different contextual filter data for nodes #2+.
Here's my exported test rule, updated to show the difference between what Views Rules is returning and "VBO's Load a list of entity IDs from a view" results.
{ "rules_views_rules_test" : {
"LABEL" : "Views Rules Test",
"PLUGIN" : "reaction rule",
"REQUIRES" : [ "rules", "views_rules", "php", "views_bulk_operations" ],
"ON" : [ "node_insert" ],
"IF" : [
{ "node_is_of_type" : { "node" : [ "node" ], "type" : { "value" : { "article" : "article" } } } },
{ "entity_has_field" : { "entity" : [ "node" ], "field" : "field_legacy_id" } },
{ "NOT data_is_empty" : { "data" : [ "node:field-legacy-id" ] } }
],
"DO" : [
{ "VIEW LOOP" : {
"VIEW" : "media_orphans",
"DISPLAY" : "views_rules_2",
"USING" : { "field_legacy_id_value" : [ "node:field-legacy-id" ] },
"ROW VARIABLES" : {
"title" : { "title" : "Content: Title" },
"nid" : { "nid" : "Nid" },
"body" : { "body" : "Body" },
"field_image_credit" : { "field_image_credit" : "Credit" },
"sticky" : { "sticky" : "Sticky" }
},
"DO" : [
{ "drupal_message" : { "message" : "Node field passed to view: [node:field-legacy-id], Item returned: \u003C?php echo $nid; ?\u003E" } }
]
}
},
{ "views_bulk_operations_action_load_id_list" : {
"USING" : {
"view" : "media_orphans|views_rules_2",
"args" : [ "node:field-legacy-id" ]
},
"PROVIDE" : { "entity_id_list" : { "entity_id_list" : "A list of entity ids" } }
}
},
{ "LOOP" : {
"USING" : { "list" : [ "entity-id-list" ] },
"ITEM" : { "list_item" : "Current list item" },
"DO" : [
{ "drupal_message" : { "message" : "[node:field-legacy-id]: \u003C?php echo $list_item; ?\u003E" } }
]
}
}
]
}
}
Here are the messages displayed by the rule, showing that the Views results (items returned) for subsequent passed filter criteria are always the same as the first filter criteria passed:
Node field passed to view: 4049276B-C29C-DD41-A26977D6D576B659, Item returned: 58307
Node field passed to view: 4049276B-C29C-DD41-A26977D6D576B659, Item returned: 58306
Node field passed to view: 4049276B-C29C-DD41-A26977D6D576B659, Item returned: 58305
4049276B-C29C-DD41-A26977D6D576B659: 58307
4049276B-C29C-DD41-A26977D6D576B659: 58306
4049276B-C29C-DD41-A26977D6D576B659: 58305
Node field passed to view: 1F409A1C-C29C-DD41-ADBCE5398636B8F8, Item returned: 58307
Node field passed to view: 1F409A1C-C29C-DD41-ADBCE5398636B8F8, Item returned: 58306
Node field passed to view: 1F409A1C-C29C-DD41-ADBCE5398636B8F8, Item returned: 58305
1F409A1C-C29C-DD41-ADBCE5398636B8F8: 58309
1F409A1C-C29C-DD41-ADBCE5398636B8F8: 58308
Node field passed to view: 0C56B78E-C29C-DD41-A3A8E138FAA845AF, Item returned: 58307
Node field passed to view: 0C56B78E-C29C-DD41-A3A8E138FAA845AF, Item returned: 58306
Node field passed to view: 0C56B78E-C29C-DD41-A3A8E138FAA845AF, Item returned: 58305
0C56B78E-C29C-DD41-A3A8E138FAA845AF: 58312
0C56B78E-C29C-DD41-A3A8E138FAA845AF: 58311
0C56B78E-C29C-DD41-A3A8E138FAA845AF: 58310
Node field passed to view: 30D6E1D2-C29C-DD41-A452DCEDB2B3CC42, Item returned: 58307
Node field passed to view: 30D6E1D2-C29C-DD41-A452DCEDB2B3CC42, Item returned: 58306
Node field passed to view: 30D6E1D2-C29C-DD41-A452DCEDB2B3CC42, Item returned: 58305
Node field passed to view: 9FC8F3DB-C29C-DD41-A857F58DD4B685A9, Item returned: 58307
Node field passed to view: 9FC8F3DB-C29C-DD41-A857F58DD4B685A9, Item returned: 58306
Node field passed to view: 9FC8F3DB-C29C-DD41-A857F58DD4B685A9, Item returned: 58305
9FC8F3DB-C29C-DD41-A857F58DD4B685A9: 58314
9FC8F3DB-C29C-DD41-A857F58DD4B685A9: 58313
Created 5 nodes.
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | 1684986-03-view-result-cache.patch | 3.6 KB | zhangtaihao |
| #3 | 1684986-03-view-result-cache-test.patch | 849 bytes | zhangtaihao |
Comments
Comment #1
zhangtaihao commentedI have managed to reproduce the issue. Debugging now.
Comment #2
zhangtaihao commentedOkay, so it turns out my original idea about using a view display directly as an iterator didn't work.Some refactoring is in order.EDIT: Perhaps not. A display can work as an iterator. The loop just has to get a new iterator.
Comment #3
zhangtaihao commentedTentative fix. Second patch contains just tests.
Comment #5
zhangtaihao commentedCommitted (9dd5471).
Comment #6
derekw commentedYou nailed it. Fixed with Beta 2.
Comment #7.0
(not verified) commentedUpdated rule to show what VBO is returning