You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Dec 13, 2020. It is now read-only.
When using this helper library to unit test some celery tasks with eager_mode (I know this is not recommended but it fits my case), it can happen that SQLAlchemy model instances become unpersistent due to a new application context.
The typical scenario is:
code creates a model instance and commits it
a celery task is called in eager_mode
the remaining non-celery code now has a detached model instance and can fail with DetachedInstanceError: Instance <SomeClass at 0x...> is not bound to a Session; attribute refresh operation cannot proceed
When using this helper library to unit test some celery tasks with eager_mode (I know this is not recommended but it fits my case), it can happen that SQLAlchemy model instances become unpersistent due to a new application context.
The typical scenario is:
DetachedInstanceError: Instance <SomeClass at 0x...> is not bound to a Session; attribute refresh operation cannot proceed
After banging my head for a whole afternoon I found some who had a similar problem https://blog.fossasia.org/detachedinstanceerror-dealing-with-celery-flasks-app-context-and-sqlalchemy/
In brief that this could be easily avoided if the
ContextTask
is created as:Would this modification be sensible for this helper package? If so, I will gladly make a PR.
The text was updated successfully, but these errors were encountered: