jeancochrane / pytest-flask-sqlalchemy

A pytest plugin for preserving test isolation in Flask-SQLAlchemy using database transactions.
MIT License
255 stars 45 forks source link

call make_transient on instance during rehydration if adding fails #41

Closed c0state closed 3 years ago

c0state commented 4 years ago

I'm getting this exception https://github.com/sqlalchemy/sqlalchemy/blob/rel_1_3_19/lib/sqlalchemy/orm/session.py#L2343 in some of my tests where a record is accessed and then deleted. Per the upstream recommendation, this captures that exception and tries calling make_transient instead.

All other errors are (re-)thrown

c0state commented 3 years ago

@jeancochrane thoughts?

c0state commented 3 years ago

Great catch here @c0state, are you able to share a quick test that we might be able to use to verify this change does what we expect?

One of my tests in a private repo fails. This PR definitely fixes it, but I'm unsure why at the moment TBH.

I think https://github.com/jeancochrane/pytest-flask-sqlalchemy/issues/25 also is similar. The comment about the flask test client causing this matches my experience. It seems removing the add call would work too--unsure where it's used or why it's needed though.