It's likely that since this creates the expression on an attribute change that only in the next "idle" state or upon a certain event post-process the expression gets added by Maya.
Unfortunately I've found no way to actually make this process correctly. Here's some things I quickly tried:
(Somehow I'm not getting the WYSIWYG editor, so I'm not sure code formatting will work)
[CODE]
import maya.mel
from PySide2 import QtWidgets
import time
# Part01
img = cmds.imagePlane()
frame_ext_attr = "{0}.useFrameExtension".format(img[0])
cmds.setAttr(frame_ext_attr, True)
# Force update? (tests)
for x in range(2):
# Run twice so "any order" of commands after each other
# is run and tested.
QtWidgets.QApplication.instance().processEvents()
cmds.refresh(force=True)
maya.utils.processIdleEvents()
maya.mel.eval("refreshAE;")
maya.mel.eval("updateMainWindowComponentState();")
time.sleep(0.05)
# Part02
print '>>> ', cmds.listConnections("{0}.frameExtension".format(img[1]))
[/CODE]