sqlalchemy.orm.exc.DetachedInstanceError:

Hello!
I’m having this error:

“sqlalchemy.orm.exc.DetachedInstanceError: Instance <DbAuthInfo at 0x7f49b4a83190> is not bound to a Session; attribute refresh operation cannot proceed (Background on this error at: Error Messages — SQLAlchemy 1.4 Documentation)”

of all my process in AiiDa list in a specific group. They are all finished (I chek going to the computer) but not retrieved from AiiDa. And I’m getting similar error for the process in a different group if I try to pause, but nothing on the verdi process report.:

“Error: failed to pause Process<371560>: Instance <DbNode at 0x7fee8eb5d900> is not bound to a Session; attribute refresh operation cannot proceed (Background on this error at: Error Messages — SQLAlchemy 1.4 Documentation)”

I’m running Aiida in a conda environment that was correclty working until yesterday.
Yesterday I created a new conda environment with a new AiiDa, changing the aiida path and exporting the new path in the correct environment.

The verdi status is ok.

The full error I get with “verdi process report” is below.

Thanks a lot in advance for any help!

Best
Chiara Cignarella

±> ERROR at 2023-12-07 17:06:17.551691+01:00
| Traceback (most recent call last):
| File “/home/cignarella/micromamba/envs/sscha/lib/python3.10/site-packages/aiida/engine/utils.py”, line 187, in exponential_backoff_retry
| result = await coro()
| File “/home/cignarella/micromamba/envs/sscha/lib/python3.10/site-packages/aiida/engine/processes/calcjobs/tasks.py”, line 192, in do_update
| with job_manager.request_job_info_update(authinfo, job_id) as update_request:
| File “/home/cignarella/micromamba/envs/sscha/lib/python3.10/contextlib.py”, line 135, in enter
| return next(self.gen)
| File “/home/cignarella/micromamba/envs/sscha/lib/python3.10/site-packages/aiida/engine/processes/calcjobs/manager.py”, line 286, in request_job_info_update
| with self.get_jobs_list(authinfo).request_job_info_update(job_id) as request:
| File “/home/cignarella/micromamba/envs/sscha/lib/python3.10/contextlib.py”, line 135, in enter
| return next(self.gen)
| File “/home/cignarella/micromamba/envs/sscha/lib/python3.10/site-packages/aiida/engine/processes/calcjobs/manager.py”, line 167, in request_job_info_update
| self._ensure_updating()
| File “/home/cignarella/micromamba/envs/sscha/lib/python3.10/site-packages/aiida/engine/processes/calcjobs/manager.py”, line 195, in _ensure_updating
| self._get_next_update_delay(),
| File “/home/cignarella/micromamba/envs/sscha/lib/python3.10/site-packages/aiida/engine/processes/calcjobs/manager.py”, line 230, in _get_next_update_delay
| minimum_interval = self.get_minimum_update_interval()
| File “/home/cignarella/micromamba/envs/sscha/lib/python3.10/site-packages/aiida/engine/processes/calcjobs/manager.py”, line 79, in get_minimum_update_interval
| return self._authinfo.computer.get_minimum_job_poll_interval()
| File “/home/cignarella/micromamba/envs/sscha/lib/python3.10/site-packages/aiida/orm/authinfos.py”, line 87, in computer
| return entities.from_backend_entity(computers.Computer, self._backend_entity.computer)
| File “/home/cignarella/micromamba/envs/sscha/lib/python3.10/site-packages/aiida/storage/psql_dos/orm/authinfos.py”, line 74, in computer
| return self.backend.computers.ENTITY_CLASS.from_dbmodel(self.model.dbcomputer, self.backend)
| File “/home/cignarella/micromamba/envs/sscha/lib/python3.10/site-packages/aiida/storage/psql_dos/orm/utils.py”, line 84, in getattr
| if self.is_saved() and self._is_mutable_model_field(item) and not self._in_transaction():
| File “/home/cignarella/micromamba/envs/sscha/lib/python3.10/site-packages/aiida/storage/psql_dos/orm/utils.py”, line 110, in is_saved
| return self.model.id is not None
| File “/home/cignarella/micromamba/envs/sscha/lib/python3.10/site-packages/sqlalchemy/orm/attributes.py”, line 487, in get
| return self.impl.get(state, dict
)
| File “/home/cignarella/micromamba/envs/sscha/lib/python3.10/site-packages/sqlalchemy/orm/attributes.py”, line 959, in get
| value = self._fire_loader_callables(state, key, passive)
| File “/home/cignarella/micromamba/envs/sscha/lib/python3.10/site-packages/sqlalchemy/orm/attributes.py”, line 990, in _fire_loader_callables
| return state._load_expired(state, passive)
| File “/home/cignarella/micromamba/envs/sscha/lib/python3.10/site-packages/sqlalchemy/orm/state.py”, line 712, in _load_expired
| self.manager.expired_attribute_loader(self, toload, passive)
| File “/home/cignarella/micromamba/envs/sscha/lib/python3.10/site-packages/sqlalchemy/orm/loading.py”, line 1369, in load_scalar_attributes
| raise orm_exc.DetachedInstanceError(
| sqlalchemy.orm.exc.DetachedInstanceError: Instance <DbAuthInfo at 0x7f49b4a83190> is not bound to a Session; attribute refresh operation cannot proceed (Background on this error at: Error Messages — SQLAlchemy 1.4 Documentation)
±> WARNING at 2023-12-07 17:06:17.556282+01:00
| maximum attempts 5 of calling do_update, exceeded.

This looks to be an instance of this bug. Did you try to restart your daemon with verdi daemon restart --reset and then when it is running again run verdi process play --all to play all the paused processes? I think that might solve it at least temporarily.

As for a real solution, I wrote a tentative fix for this bug (see this branch). If you’d like, you can checkout that branch and install it and it should fix the problem. If you can confirm this worked, that would be great, because then I can open a PR and merge it into the main branch to get it released.

Thanks Sebastian,
restarting with --reset works for now. I’ll try with the new branch as soon as I finish my results with this one, and I’ll keep you posted.

Thanks
Chiara

1 Like