Is there a way to get a list of Factory Boy subfactory objects from with the correct Django object type?

I have a factory boy factory that uses Django. I need to access a list of the generated objects from a SubFactory. However, whenever I attempt to get that list, I receive TypeErrors that say that my generated objects are "SubFactory" instead of the type of the object I actually need. Any idea what I'm missing?

class PartNoRelationFactory(factory.django.DjangoModelFactory):
    class Meta:
        model = PartNoRelation

    id = factory.Sequence(lambda n: n + 1)

    parent_part_no = factory.SubFactory(PART_NO_FACTORY)
    child_part_no = factory.SubFactory(PART_NO_FACTORY)

def mock_child_part_nos(arg_1: PartNo) -> 'list[PartNo]':
    mock_part_no_relation_one = PartNoRelationFactory()
    mock_part_no_relation_two = PartNoRelationFactory()
    mock_part_no_relation_three = PartNoRelationFactory()

    return [
    # error: "Expression of type "list[SubFactory]" cannot be assigned to return type "list[PartNo]"

Back to Top