# Buggy code
def append(self, instruction, qargs=None, cargs=None):
    """Append one or more instructions to the end of the circuit, modifying
    the circuit in place. Expands qargs and cargs.

    Args:
        instruction (qiskit.circuit.Instruction): Instruction instance to append
        qargs (list(argument)): qubits to attach instruction to
        cargs (list(argument)): clbits to attach instruction to

    Returns:
        qiskit.circuit.Instruction: a handle to the instruction that was just added

    Raises:
        CircuitError: if object passed is a subclass of Instruction
        CircuitError: if object passed is neither subclass nor an instance of Instruction
    """
    # Convert input to instruction
    if not isinstance(instruction, Instruction) and not hasattr(
        instruction, "to_instruction"
    ):
        if issubclass(instruction, Instruction):
            raise CircuitError(
                "Object is a subclass of Instruction, please add () to "
                "pass an instance of this object."
            )

        raise CircuitError(
            "Object to append must be an Instruction or have a to_instruction() method."
        )
    if not isinstance(instruction, Instruction) and hasattr(
        instruction, "to_instruction"
    ):
        instruction = instruction.to_instruction()

    expanded_qargs = [self.qbit_argument_conversion(qarg) for qarg in qargs or []]
    expanded_cargs = [self.cbit_argument_conversion(carg) for carg in cargs or []]

    instructions = InstructionSet()
    for qarg, carg in instruction.broadcast_arguments(expanded_qargs, expanded_cargs):
        instructions.add(self._append(instruction, qarg, carg), qarg, carg)
    return instructions


# Traceback (KeyError)
from qiskit.circuit.library import RXGate
from qiskit.circuit import QuantumCircuit, Parameter
a, b = Parameter('a'), Parameter('b')
rx = RXGate(a)
qc0, qc1 = QuantumCircuit(1), QuantumCircuit(1)
qc0.append(rx, [0])
qc1.append(rx, [0])
qc0.assign_parameters({a: b}, inplace=True)
qc1.to_gate()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/jul/Work/Qiskit/qiskit-terra/qiskit/circuit/quantumcircuit.py", line 836, in to_gate
return circuit_to_gate(self, parameter_map, label=label)
File "/Users/jul/Work/Qiskit/qiskit-terra/qiskit/converters/circuit_to_gate.py", line 88, in circuit_to_gate
target = circuit.assign_parameters(parameter_dict, inplace=False)
File "/Users/jul/Work/Qiskit/qiskit-terra/qiskit/circuit/quantumcircuit.py", line 1669, in assign_parameters
bound_circuit._substitute_parameter(parameter, value)
File "/Users/jul/Work/Qiskit/qiskit-terra/qiskit/circuit/quantumcircuit.py", line 1735, in _substitute_parameter
new_param = instr.params[param_index].subs({old_parameter: new_parameter_expr})
File "/Users/jul/Work/Qiskit/qiskit-terra/qiskit/circuit/parameter.py", line 55, in subs
return parameter_map[self]
KeyError: Parameter(b)

# Fixed code
def append(self, instruction, qargs=None, cargs=None):
    """Append one or more instructions to the end of the circuit, modifying
    the circuit in place. Expands qargs and cargs.

    Args:
        instruction (qiskit.circuit.Instruction): Instruction instance to append
        qargs (list(argument)): qubits to attach instruction to
        cargs (list(argument)): clbits to attach instruction to

    Returns:
        qiskit.circuit.Instruction: a handle to the instruction that was just added

    Raises:
        CircuitError: if object passed is a subclass of Instruction
        CircuitError: if object passed is neither subclass nor an instance of Instruction
    """
    # Convert input to instruction
    if not isinstance(instruction, Instruction) and not hasattr(
        instruction, "to_instruction"
    ):
        if issubclass(instruction, Instruction):
            raise CircuitError(
                "Object is a subclass of Instruction, please add () to "
                "pass an instance of this object."
            )

        raise CircuitError(
            "Object to append must be an Instruction or have a to_instruction() method."
        )
    if not isinstance(instruction, Instruction) and hasattr(
        instruction, "to_instruction"
    ):
        instruction = instruction.to_instruction()

    # Make copy of parameterized gate instances
    if hasattr(instruction, "params"):
        is_parameter = any(
            [isinstance(param, Parameter) for param in instruction.params]
        )
        if is_parameter:
            instruction = copy.deepcopy(instruction)

    expanded_qargs = [self.qbit_argument_conversion(qarg) for qarg in qargs or []]
    expanded_cargs = [self.cbit_argument_conversion(carg) for carg in cargs or []]

    instructions = InstructionSet()
    for qarg, carg in instruction.broadcast_arguments(expanded_qargs, expanded_cargs):
        instructions.add(self._append(instruction, qarg, carg), qarg, carg)
    return instructions