Review generated work-order copier

from Shallow and deep copy
Python 3.14 advanced 6 min 4 issues to find

Review this generated work-order copier against the stated ownership policy and identify four distinct risks.

Duplicate a work order, preserve aliases and cycles among mutable steps, share the read-only catalog, create a fresh lock, and allow callers to change only the order ID.

Python
import copy
import threading

class WorkOrder:
    def __init__(self, order_id, steps, catalog):
        self.order_id = order_id
        self.steps = steps
        self.catalog = catalog
        self.lock = threading.Lock()

    def __deepcopy__(self, memo):
        clone = type(self)(
            self.order_id,
            [copy.deepcopy(step) for step in self.steps],
            copy.deepcopy(self.catalog, memo),
        )
        clone.lock = copy.deepcopy(self.lock, memo)
        return clone

def duplicate_order(template, changes):
    clone = copy.deepcopy(template)
    clone.__dict__.update(changes)
    return clone

generated code is illustrative, not from any one model

Open in playground
Report an error