Refresh an F-curve with Python after changing Extrapolation Mode After creating an F-curve for the default cube and then setting the Extrapolation Mode to 'LINEAR', the graph editor displays a very strange curve:



The script I ran in the Text Editor of a  new .blend file was:

import bpy

obj = bpy.context.object
obj.animation_data_create()
obj.animation_data.action = bpy.data.actions.new(name="MyAction")
fcu_z = obj.animation_data.action.fcurves.new(data_path="location", index=2)
fcu_z.keyframe_points.add(2)
fcu_z.keyframe_points[0].co = 10.0, 0.0
fcu_z.keyframe_points[1].co = 20.0, 1.0

fcu_z.extrapolation='LINEAR'


The F-curve can be manually "refreshed" by selecting a control point and hitting GRMB.



So my questions are:


Can I "refresh" the F-curve in the script?
Should I submit a bug report?
You don't set the coordinates for the handles.

Blender won't check if these are valid. In this case the right handle is initialized with the default value
(0.0, 0.0) which is invalid since the  x-coordinate of the left endpoint is 10.0. So handle_x > endpoint_x is violated here. 

Moving the point blender will automatically recalculate the handles for the points.

BTW: keyframe_points.insert will recalculate the curve unless the option FAST is chosen.

This example works:

import bpy

obj = bpy.context.object
obj.animation_data_create()
obj.animation_data.action = bpy.data.actions.new(name="MyAction")
fcu_z = obj.animation_data.action.fcurves.new(data_path="location", index=2)
fcu_z.extrapolation='LINEAR'
fcu_z.keyframe_points.insert(10.0, 0.0)
fcu_z.keyframe_points.insert(20.0, 1.0)