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 ee8d278
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 15 deletions.
13 changes: 1 addition & 12 deletions factory/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import importlib.metadata

from . import alchemy, mogo, mongoengine
from .base import (
BaseDictFactory,
BaseListFactory,
Expand Down Expand Up @@ -54,22 +55,10 @@
stub_batch,
)

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

__author__ = 'Raphaël Barrois <raphael.barrois+fboy@polytechnique.org>'
__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 ee8d278

Please sign in to comment.