Skip to content

Commit ee8d278

Browse files
committed
Defer sqlalchemy import
1 parent dca3a16 commit ee8d278

2 files changed

Lines changed: 4 additions & 15 deletions

File tree

factory/__init__.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import importlib.metadata
44

5+
from . import alchemy, mogo, mongoengine
56
from .base import (
67
BaseDictFactory,
78
BaseListFactory,
@@ -54,22 +55,10 @@
5455
stub_batch,
5556
)
5657

57-
try:
58-
from . import alchemy
59-
except ImportError:
60-
pass
6158
try:
6259
from . import django
6360
except ImportError:
6461
pass
65-
try:
66-
from . import mogo
67-
except ImportError:
68-
pass
69-
try:
70-
from . import mongoengine
71-
except ImportError:
72-
pass
7362

7463
__author__ = 'Raphaël Barrois <raphael.barrois+fboy@polytechnique.org>'
7564
__version__ = importlib.metadata.version("factory_boy")

factory/alchemy.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
# Copyright: See the LICENSE file.
22

3-
from sqlalchemy.exc import IntegrityError
4-
from sqlalchemy.orm.exc import NoResultFound
5-
63
from . import base, errors
74

85
SESSION_PERSISTENCE_COMMIT = 'commit'
@@ -64,6 +61,9 @@ def _generate(cls, strategy, params):
6461

6562
@classmethod
6663
def _get_or_create(cls, model_class, session, args, kwargs):
64+
from sqlalchemy.exc import IntegrityError
65+
from sqlalchemy.orm.exc import NoResultFound
66+
6767
key_fields = {}
6868
for field in cls._meta.sqlalchemy_get_or_create:
6969
if field not in kwargs:

0 commit comments

Comments
 (0)