1

I am having trouble with part of my code and it stems from the attributes not updating when I believe they should be updating.

                    if str(f[t1st])==str(f2[start_index]):
                        layer.startEditing()
                        layer.changeAttributeValue(f2.id(),t1st, str(f2[end_index]))
                        layer.changeAttributeValue(f2.id(),t2nd, str(f2[start_index]))
                        layer.commitChanges()
                        print f2[end_index]
                        print f2[t2nd]

This is in the middle of a for loop. The first print statement returns the correct value but the second print value is always NULL. If create a for loop right after, the attributes show as updated and not NULL. Shouldn't the attributes update after I the layer.commitChanges() line? When will the attributes update?

1
  • 1
    I can't see the asignments to f and f2, are they feature objects? Where is t2nd set? I think we need to see more of your code... Jul 10, 2018 at 17:22

1 Answer 1

2

They update immediately, but any existing features (such as f2 in your code) are copies of the layer's features at the time they were retrieved. So you need to refetch the feature to see the newly saved changes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.