Problems appending collection multiple times using Python in Blender 2.9

Howdy,

I’ve been running into issues appending a collection multiple times from another blender file using Python. (Blender version 2.90.1)

I’ve tried using ‘bpy.ops.wm.append(filename=collection_name, directory=path)
the code gets accepted and returns {“FINISHED”} but it doesn’t seem to do anything.

I’ve also tried the long way around:

with bpy.data.libraries.load(filepath, link=False) as ( _, data_to):    
    data_to.objects =  ['part_1', 'part_2', 'part_3', 'part_4']
  
collection = bpy.data.collections.new(f'component_collection_{i}')
bpy.context.scene.collection.children.link(collection) 

for obj in data_to.objects:       
    if obj:
        collection.objects.link(obj)

Which imports the collection once perfectly fine, however when I run the code a second time all the objects in the data_to change to None

I’ve also tried setting ‘_’ and ‘data_to’ to None afterwards to see if the with statement would release the file but that doesn’t work.

I’ve also tried just copying the imported collection but I’m having issues creating a new copy of it and copying all of the relationship and constraint data to the new collection.

Any help would be much appreciated, this has been driving me insane

Thanks in advance