Fix: "NameError: global name '_unique_idx' is not defined"