Different behavior when looping through a list of variables
Make sure your section.first() returns an element. The error occurs because section.first() is null => no element was found with your criteria. And the value null has no function getSection.

However - keep in mind your sectionHandle variable is not the handle of the section, but the SectionModelthus your code as it is currently is not really performant