diff --git a/factory/alchemy.py b/factory/alchemy.py index 4e7ad6a2..f934ce5d 100644 --- a/factory/alchemy.py +++ b/factory/alchemy.py @@ -24,8 +24,11 @@ def _check_sqlalchemy_session_persistence(self, meta, value): @staticmethod def _check_has_sqlalchemy_session_set(meta, value): - if value and meta.sqlalchemy_session: - raise RuntimeError("Provide either a sqlalchemy_session or a sqlalchemy_session_factory, not both") + try: + if value and meta.sqlalchemy_session: + raise RuntimeError("Provide either a sqlalchemy_session or a sqlalchemy_session_factory, not both") + except AttributeError: + pass def _build_default_options(self): return super()._build_default_options() + [ diff --git a/tests/test_alchemy.py b/tests/test_alchemy.py index 9cac036b..19e4f5ee 100644 --- a/tests/test_alchemy.py +++ b/tests/test_alchemy.py @@ -286,7 +286,6 @@ def test_create_get_session_from_sqlalchemy_session_factory(self): class SessionGetterFactory(SQLAlchemyModelFactory): class Meta: model = models.StandardModel - sqlalchemy_session = None sqlalchemy_session_factory = lambda: models.session id = factory.Sequence(lambda n: n)