Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ORM: Filter inconsequential warnings from
sqlalchemy
(#6192)
Recently, the code was updated to be compatible with `sqlalchmey~=2.0` which caused a lot of warnings to be emitted. As of `sqlalchemy==2.0.19` the `sqlalchemy.orm.unitofwork.UOWTransaction.register_object` method emits a warning whenever an object is registered that is not part of the session. See for details: https://docs.sqlalchemy.org/en/20/changelog/changelog_20.html#change-53740fe9731bbe0f3bb71e3453df07d3 This can happen when the session is committed or flushed and an object inside the session contains a reference to another object, for example through a relationship, is not explicitly part of the session. If that referenced object is not already stored and persisted, it might get lost. On the other hand, if the object was already persisted before, there is no risk. This situation occurs a lot in AiiDA's code base. Prime example is when a new process is created. Typically the input nodes are either already stored, or stored first. As soon as they get stored, the session is committed and the session is reset by expiring all objects. Now, the input links are created from the input nodes to the process node, and at the end the process node is stored to commit and persist it with the links. It is at this point that Sqlalchemy realises that the input nodes are not explicitly part of the session. One direct solution would be to add the input nodes again to the session before committing the process node and the links. However, this code is part of the backend independent :mod:`aiida.orm` module and this is a backend-specific problem. This is also just one example and there are most likely other places in the code where the problem arises. Therefore, as a workaround, a warning filter is put in place to silence this particular warning. Note that `pytest` undoes all registered warning filters, so it has to be added again in the `pytest` configuration in the `pyproject.toml`.
- Loading branch information