-
Notifications
You must be signed in to change notification settings - Fork 239
Issue #6687 Fix QueryBuilder filtering for AbstractCode #6857
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -852,6 +852,58 @@ def test_empty_filters(self): | |
| qb = orm.QueryBuilder().append(orm.Data, filters={'or': [{}, {}]}) | ||
| assert qb.count() == count | ||
|
|
||
| @pytest.mark.usefixtures('aiida_profile_clean') | ||
| def test_abstract_code_filtering(self, tmp_path): | ||
| """Test that querying for AbstractCode correctly returns all code instances. | ||
|
|
||
| This tests the fix for issue #6687, where QueryBuilder couldn't find codes | ||
| when looking for AbstractCode due to a node_type mismatch. | ||
| """ | ||
| # Set up test environment | ||
|
|
||
| computer = orm.Computer( | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should use existing test fixtures here instead of managing manually, e.g.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think in this case yes, you can just use them. When I had a go I was not yet sure what the test should do. Sometimes you need a computer with a specific label or so. But in this case the fixture should be usable. |
||
| label='test_computer_abstract', | ||
| hostname='localhost', | ||
| transport_type='core.local', | ||
| scheduler_type='core.direct', | ||
| ).store() | ||
|
|
||
| # Create test codes of different types | ||
| installed_code = orm.InstalledCode( | ||
| label='test_installed_abstract', | ||
| computer=computer, | ||
| filepath_executable='/bin/bash', | ||
| ).store() | ||
|
|
||
| (tmp_path / 'exec').touch() | ||
| portable_code = orm.PortableCode( | ||
| label='test_portable_abstract', | ||
| filepath_executable='exec', | ||
| filepath_files=tmp_path, | ||
| ).store() | ||
|
|
||
| # Test 1: AbstractCode query should find all code types | ||
| qb_abstract = orm.QueryBuilder().append(orm.AbstractCode) | ||
| abstract_results = qb_abstract.all(flat=True) | ||
| assert ( | ||
| installed_code in abstract_results | ||
| ), f'InstalledCode not found with AbstractCode query. Result: {abstract_results}' | ||
| assert ( | ||
| portable_code in abstract_results | ||
| ), f'PortableCode not found with AbstractCode query. Result: {abstract_results}' | ||
|
|
||
| # Test 2: Verify specific code type queries work as expected | ||
| qb_installed = orm.QueryBuilder().append(orm.InstalledCode) | ||
| installed_results = qb_installed.all(flat=True) | ||
| assert installed_code in installed_results | ||
| assert portable_code not in installed_results | ||
|
|
||
| # Test 3: Test with basic filtering | ||
| qb_filtered = orm.QueryBuilder().append(orm.AbstractCode, filters={'label': 'test_installed_abstract'}) | ||
| filtered_results = qb_filtered.all(flat=True) | ||
| assert len(filtered_results) == 1 | ||
| assert installed_code in filtered_results | ||
|
|
||
|
|
||
| class TestAttributes: | ||
| @pytest.mark.requires_psql | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please keep this comment