Sculpt programatically poll() context is incorrect

Anyone? I’m also having this same problem. As far as I can tell I am in SCULPT mode and yet this error still occurs. Is it a Blender bug?