4

I have been using the following Python code on QGIS 3 (2.99) to look up fields, for several months

id = feature.attributes()[layer.pendingFields().lookupField('ID')]

And it gives me an error today:

AttributeError: 'QgsVectorLayer' object has no attribute 'pendingFields'

Is this another breaking change in the QGIS development version? And what's the correct way to write it now?

Taras
  • 32,823
  • 4
  • 66
  • 137
tinlyx
  • 11,057
  • 18
  • 71
  • 119

1 Answers1

8

The answer seems to be yes, another change in QGIS 2.99.

I saw a question (not available) from @Andreas Neumann on the qgis-dev mailing list regarding the same question.

@Etienne Trimaille and @Alessandro Pasotti reveal that pendingFields() is removed and suggest that you instead should use fields().

Taras
  • 32,823
  • 4
  • 66
  • 137
Chau
  • 4,480
  • 4
  • 39
  • 57