Skip to content

Conversation

@adityagh006
Copy link
Contributor

This PR fixes an issue in QueryBuilder where filtering for AbstractCode was not working correctly. The update ensures that queries involving AbstractCode return expected results.

Changes Made:
1.Fixed filtering logic in querybuilder.py.
2.Updated pyproject.toml accordingly.

Let me know if any additional changes are needed.

Copy link
Collaborator

@danielhollas danielhollas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the contribution @adityagh006! 👏

This will need tests, which should cover various types of codes as described in the issue. Hopefully the existing QueryBuilder tests in aiida-core/tests/orm/test_querybuilder.py can help you get started. Let us now if you need assistance!

Comment on lines 1339 to 1347
# value = classifiers.ormclass_type_string

# if not subclassing:
# filters = {'==': value}
# else:
# # Note: the query_type_string always ends with a dot. This ensures that "like {str}%" matches *only*
# # the query type string
# filters = {'like': f'{escape_for_sql_like(get_query_type_from_type_string(value))}%'}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove all commented out code (also below)

Suggested change
# value = classifiers.ormclass_type_string
# if not subclassing:
# filters = {'==': value}
# else:
# # Note: the query_type_string always ends with a dot. This ensures that "like {str}%" matches *only*
# # the query type string
# filters = {'like': f'{escape_for_sql_like(get_query_type_from_type_string(value))}%'}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, sorry for that! I forgot to remove those comments. I'll take care of it in the next update.


value = classifiers.ormclass_type_string

if value == 'data.core.code.abstract':
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this needs a longer comment to explain this corner case. You can perhaps reuse part of the explanation from the issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it! I'll add a detailed comment explaining this corner case, incorporating relevant details from the issue.

@danielhollas
Copy link
Collaborator

Hi @adityagh006, are you still planning to work on this PR? I think the code looks good (though I haven't tested it personally) but it needs unit tests.

@adityagh006
Copy link
Contributor Author

@danielhollas! I’ve written some test cases for the AbstractCode filtering, but I’m having trouble getting them to run properly. I’ve tried a few things, but I'm not sure if it’s an environment issue or something else—I’m a bit stuck at the moment.

@danielhollas
Copy link
Collaborator

@adityagh006 no worries. Feel free to push what you have and I can have a look.

@codecov
Copy link

codecov bot commented Apr 23, 2025

Codecov Report

Attention: Patch coverage is 50.00000% with 1 line in your changes missing coverage. Please review.

Project coverage is 78.31%. Comparing base (660fec7) to head (75c62d4).

Files with missing lines Patch % Lines
src/aiida/orm/querybuilder.py 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6786      +/-   ##
==========================================
- Coverage   78.31%   78.31%   -0.00%     
==========================================
  Files         566      566              
  Lines       42762    42764       +2     
==========================================
+ Hits        33484    33485       +1     
- Misses       9278     9279       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@adityagh006
Copy link
Contributor Author

@danielhollas! I’m currently caught up with a college assignment, but I’ll make sure to push the test cases by end of day tomorrow.

@adityagh006 adityagh006 force-pushed the issue-6687 branch 2 times, most recently from 607c854 to ac57010 Compare April 25, 2025 19:09
Copy link
Collaborator

@danielhollas danielhollas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adityagh006 can you please rebase this PR on latest main? It now contains some extra commits.

The logic of the new tests looks good! Just needs a couple of fixes, see my comments. Let me know if you need further help, and thanks for working through this!


portable_code = orm.PortableCode(
label='test_portable_abstract',
filepath_executable='/bin/bash',
Copy link
Collaborator

@danielhollas danielhollas Apr 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this needs to be fixed, please look at existing tests in tests/orm/data/code/test_portable.py

Suggested change
filepath_executable='/bin/bash',
filepath_paths='/bin/bash',

when looking for AbstractCode due to a node_type mismatch.
"""
# Set up test environment
computer = orm.Computer(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use an existing fixture aiida_computer_local to simplify this. You can then delete the cleanup code since the fixture does that automatically at the end of the test.

qb = orm.QueryBuilder().append(orm.Data, filters={'or': [{}, {}]})
assert qb.count() == count

from aiida.orm import AbstractCode, Computer, InstalledCode, PortableCode, QueryBuilder
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's move these imports at the top of the file

# 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, 'InstalledCode not found with AbstractCode query'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think these asserts will work, since the objects returned by the QueryBuilder will be different from the original objects that you stored, even though they point to the same DB node. I think you should compare the id of the nodes, something like

Suggested change
assert installed_code in abstract_results, 'InstalledCode not found with AbstractCode query'
abstract_ids = [code.id for code in abstract_results]
assert installed_code.id in abstract_ids, 'InstalledCode not found with AbstractCode query'

pyproject.toml Outdated
'process.workflow.workfunction' = 'aiida.orm.nodes.process.workflow.workfunction:WorkFunctionNode'

[project.entry-points.'aiida.orm']
'core.code.abstract' = 'aiida.orm.nodes.data.code.abstract:AbstractCode'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this entry point should be moved to [project.entry-points.'aiida.data'] section where the other code entry points are defined.

pyproject.toml Outdated
[project.entry-points.'aiida.workflows']
'core.arithmetic.add_multiply' = 'aiida.workflows.arithmetic.add_multiply:add_multiply'
'core.arithmetic.multiply_add' = 'aiida.workflows.arithmetic.multiply_add:MultiplyAddWorkChain'
'core.code.abstract' = 'aiida.orm.nodes.data.code.abstract:AbstractCode'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
'core.code.abstract' = 'aiida.orm.nodes.data.code.abstract:AbstractCode'

@adityagh006
Copy link
Contributor Author

Hi @danielhollas,
I’ve been struggling to rebase the branch and push the changes due to some virtual environment issues. As a result, I mistakenly force-pushed, which caused the PR to close.
Could you please let me know what the next steps are or if there’s anything I should do to reopen or proceed with this PR?

Apologies for the inconvenience.

@danielhollas
Copy link
Collaborator

@adityagh006 feel free to open a new one.

I can help with the rebase, but there are currently no commits in this branch so I cannot...

@adityagh006
Copy link
Contributor Author

Hi @danielhollas,

Apologies for the delay, but I’ve created a new PR for the changes. You can find it here.

Let me know if any further adjustments are needed.

@adityagh006
Copy link
Contributor Author

Hi @danielhollas,
Thanks a lot for taking the PR over and seeing it through. I really appreciate your help.
I also heard that AiiDA won’t be participating in GSoC this year—sad to hear that. I had submitted a proposal for Project #2 and was really looking forward to it, but I completely understand the situation.
Thanks again!

@adityagh006 adityagh006 deleted the issue-6687 branch May 26, 2025 06:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants