Skip to content

Commit

Permalink
Don't require setting sqlalchemy_session to None when using a factory.
Browse files Browse the repository at this point in the history
  • Loading branch information
jgadling authored and francoisfreitag committed Jul 31, 2023
1 parent 2a37190 commit f83e0f6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
7 changes: 5 additions & 2 deletions factory/alchemy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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() + [
Expand Down
1 change: 0 additions & 1 deletion tests/test_alchemy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit f83e0f6

Please sign in to comment.