#612 for 4.0.x: Attributes other than String and element iterable in foreach are not supported

Closed PR 632 and reopen this one for 4.0.x and issue #612