I have added a couple of fields to a postgis table which is loaded into a layer in QGIS. When I access the attribute table in QGIS I can see the two new fields but when I run a script (using scriptrunner) to access the layer it does not show the two new fields.
I check the fields in the script by listing them:
print [field.name() for field in layer.pendingFields() ]
but the new fields are not there and I get key errors when I try and access the fields by name or index.
How can a script access something different to the QGIS gui?
QGIS 2.18.7 on a Mac.