factory_boy icon indicating copy to clipboard operation
factory_boy copied to clipboard

Defer Django and sqlalchemy imports

Open adamchainz opened this issue 1 year ago • 4 comments

Fixes #1070.

adamchainz avatar Mar 29 '24 11:03 adamchainz

Oopsie, I now realize I missed line 5 : from . import alchemy, mogo, mongoengine. Edited my previous comment.

Your suggested change is much less controversial then. :)

francoisfreitag avatar Apr 05 '24 11:04 francoisfreitag

I’m wondering if the same change should be applied to the django module?

francoisfreitag avatar Apr 05 '24 11:04 francoisfreitag

Yeah, good idea. I didn’t do it at first out of laziness. I just made the change and it wasn’t that hard!

adamchainz avatar Apr 09 '24 13:04 adamchainz

I understand the idea behind this change; however, I would prefer to have an agreement on the overall design (in the issue) before jumping into code.

At a high level, I would be OK with this kind of change if:

  • It doesn't require any change on current working code;
  • It doesn't scatter import statements throughout the codebase;
  • It breaks cleanly at module import time, not at runtime — i.e as soon as one declares a DjangoModelFactory / AlchemyModelFactory / etc, not one they get used.

Would it be possible to adjust this idea to match those? I'd rather avoid increasing the burden on maintenance for the library — including issues opened by users who don't understand why they get import errors when calling their factories…

rbarrois avatar Apr 09 '24 17:04 rbarrois