-
Notifications
You must be signed in to change notification settings - Fork 192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
extra can not be set on the fly when query the database #5672
Comments
As discussed, this appears to be a result of #5654, whereby The logic in and also @contextmanager
def use_query(self, data: QueryDictType) -> Iterator[Query]:
"""Yield the built query."""
query = self._update_query(data)
try:
yield query
except Exception:
self.get_session().close()
raise @contextmanager
def query_session(self, data: QueryDictType) -> Iterator[BuiltQuery]:
"""Yield the built query, ensuring the session is closed on an exception."""
query = self.get_query(data)
try:
yield query
except Exception:
self.get_session().close()
raise |
The confusion is understandable. This bug was not introduced by #5654 , it has existed for all of v2.0. In fact, it even existed for def test_iterall_with_mutation(self):
"""Test that nodes can be mutated while being iterated using ``QueryBuilder.iterall``."""
for node in range(2):
orm.Data().store()
for [node] in orm.QueryBuilder().append(orm.Data).iterall():
node.base.extras.set('key', 'value') The same test on v1.6.9 with Django works just fine though. Based on the answer in this thread (by the author of So fundamentally our current implementation does not allow mutating nodes during an In normal applications, the changes would be committed once at the end of the iteration. Alternatively, we might get rid of the commit in the |
The behavior is changed between
2.0.3
and2.0.4
on query. Setting the extra attributes of the node byquery.iterall()
.As reported in aiidateam/aiida-tutorials#435.
The query for the structure data and set the extras
Will cause the error:
The text was updated successfully, but these errors were encountered: