Skip to content

Commit

Permalink
Tests: Fix tests.orm.nodes.test_node:test_delete_through_backend (#…
Browse files Browse the repository at this point in the history
…6496)

The test was failing with a `core.sqlite_dos` storage plugin for the
test profile. The problem is that the last assert was checking that the
logs for `data_two` were deleted because `data_two` itself had been
deleted. However, since it was deleted, the ORM instance can no longer
be used either, which was causing an exception. Instead, its pk should
be recorded before deleting the node, and the final check should just
use the pk directly.

It is not quite clear why this test was not failing for the default
`core.psql_dos` storage plugin that is used for tests. It should not be
backend specific since both use SQLAlchemy for the ORM.
  • Loading branch information
sphuber authored Jun 30, 2024
1 parent 310ff1d commit a44e643
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions tests/orm/nodes/test_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -837,17 +837,13 @@ def test_tab_completable_properties(self):
class TestNodeDelete:
"""Tests for deleting nodes."""

# TODO: Why is this failing for SQLite??
# sqlalchemy.orm.exc.ObjectDeletedError: Instance '<DbNode at 0x7f6a68845990>' has been deleted,
# or its row is otherwise not present.
# https://github.com/aiidateam/aiida-core/issues/6436
@pytest.mark.requires_psql
def test_delete_through_backend(self):
"""Test deletion works correctly through the backend."""
backend = get_manager().get_profile_storage()

data_one = Data().store()
data_two = Data().store()
data_two_pk = data_two.pk
calculation = CalculationNode()
calculation.base.links.add_incoming(data_one, LinkType.INPUT_CALC, 'input_one')
calculation.base.links.add_incoming(data_two, LinkType.INPUT_CALC, 'input_two')
Expand All @@ -866,7 +862,7 @@ def test_delete_through_backend(self):

assert len(Log.collection.get_logs_for(data_one)) == 1
assert Log.collection.get_logs_for(data_one)[0].pk == log_one.pk
assert len(Log.collection.get_logs_for(data_two)) == 0
assert len(Log.collection.find({'dbnode_id': data_two_pk})) == 0

def test_delete_collection_logs(self):
"""Test deletion works correctly through objects collection."""
Expand Down

0 comments on commit a44e643

Please sign in to comment.