FactoryBoy / factory_boy

A test fixtures replacement for Python
https://factoryboy.readthedocs.io/
MIT License
3.51k stars 396 forks source link

Factory Boy DB connection never ends (Django) #615

Closed ChBernat closed 4 years ago

ChBernat commented 5 years ago

Description

I have quite a big and complex Factory that creates or gets many subFactories on each call and I put all the functionality into the Django Admin command. Now, whenever I'm trying to call it, it executes once and then freezes, leaving a connection to the database opened. There's no error or meaningful warning. It just freezes.

Now, I'm really not sure why this is happening but whenever I'm using subFactories of this Factory it works smoothly.

Model / Factory code

This is the main factory that causes the freeze.

class WorkEntryFactory(factory.DjangoModelFactory):
    class Meta:
        model = work.get_model('WorkEntry')
        database = 'default'

    date = factory.Faker('date_between_dates', date_start=date(date.today().year, 1, 1),
                         date_end=date(date.today().year, 12, 31))

    hours = factory.Faker('pydecimal', min_value=0, max_value=2, right_digits=1, left_digits=1)
    comments = factory.Faker('text')
    invoice = factory.SubFactory(InvoiceFactory, title="invoice")
    invoiced = factory.Faker('boolean', chance_of_getting_true=50)

    purchase_order = factory.SubFactory(PurchaseOrderFactory)

    purchase_order_work_type = factory.SubFactory(WorkTypePurchaseOrderFactory)

    offer = factory.SubFactory(OfferFactory)
    offer_work_type = factory.SubFactory(WorkTypeOfferFactory)

    issue = factory.SubFactory(IssueFactory)

    # in CHF
    user_offer_rate = factory.SubFactory(UserOfferRateFactory)

Notes

Add any notes you feel relevant here :)

rbarrois commented 5 years ago

How do you call that command?

FactoryBoy doesn't have any DB management code (at least for Django).

francoisfreitag commented 4 years ago

Closing due to inactivity.