Skip to content

Commit

Permalink
Defer sqlalchemy import
Browse files Browse the repository at this point in the history
  • Loading branch information
adamchainz committed Mar 29, 2024
1 parent dca3a16 commit a920584
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 15 deletions.
15 changes: 3 additions & 12 deletions factory/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,13 @@
stub_batch,
)

try:
from . import alchemy
except ImportError:
pass
from . import alchemy
try:
from . import django
except ImportError:
pass
try:
from . import mogo
except ImportError:
pass
try:
from . import mongoengine
except ImportError:
pass
from . import mogo
from . import mongoengine

__author__ = 'Raphaël Barrois <[email protected]>'
__version__ = importlib.metadata.version("factory_boy")
6 changes: 3 additions & 3 deletions factory/alchemy.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
# Copyright: See the LICENSE file.

from sqlalchemy.exc import IntegrityError
from sqlalchemy.orm.exc import NoResultFound

from . import base, errors

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

@classmethod
def _get_or_create(cls, model_class, session, args, kwargs):
from sqlalchemy.exc import IntegrityError
from sqlalchemy.orm.exc import NoResultFound

key_fields = {}
for field in cls._meta.sqlalchemy_get_or_create:
if field not in kwargs:
Expand Down

0 comments on commit a920584

Please sign in to comment.