Selecting a specific cube in an array to change properties
This operator does not return a reference for the created object.,
bpy.ops.mesh.primitive_cube_add(size=1, location=(i*2, 0, 0)))

so change to the following.
bpy.ops.mesh.primitive_cube_add(size=1, location=(i*2, 0, 0))
cubes.append(bpy.context.active_object)