Skip to content

Conversation

@adityagh006
Copy link
Contributor

@adityagh006 adityagh006 commented May 5, 2025

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.
3.Added pytest tests for QueryBuilder functionality, as previously requested.

Let me know if any additional changes are needed.

Closes #6687.

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 please push the tests as well.

pyproject.toml Outdated
'core.arithmetic.multiply_add' = 'aiida.workflows.arithmetic.multiply_add:MultiplyAddWorkChain'

[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.

Comment on lines 1339 to 1349
# 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))}%'}

value = classifiers.ormclass_type_string

if value == 'data.core.code.abstract':
value = 'data.core.code' # Ensure it matches all codes

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
# 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))}%'}
value = classifiers.ormclass_type_string
if value == 'data.core.code.abstract':
value = 'data.core.code' # Ensure it matches all codes

if not subclassing:
filters = {'==': value}
else:
# Note: the query_type_string always ends with a dot. This ensures that "like {str}%" matches *only*
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please keep this comment

@adityagh006 adityagh006 force-pushed the issue-6687-v2 branch 2 times, most recently from e226f59 to 1ca1da8 Compare May 5, 2025 17:56
@danielhollas
Copy link
Collaborator

@agoscinski FYI I think this one would be great to get into 2.7. What is your timeline for release?

@agoscinski
Copy link
Contributor

agoscinski commented May 7, 2025

@danielhollas well it seems that this does not fix the problem. I can query the orm.Computer in but still not the codes.
EDIT: only the orm.AbstractCode does not work, the installed and portable one works.

@agoscinski agoscinski requested a review from danielhollas May 7, 2025 10:32
"""
# 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.

We should use existing test fixtures here instead of managing manually, e.g. aiida_code or aiida_code_installed.

Copy link
Contributor

Choose a reason for hiding this comment

The 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.

@danielhollas
Copy link
Collaborator

@danielhollas well it seems that this does not fix the problem. I can query the orm.Computer in but still not the codes.
EDIT: only the orm.AbstractCode does not work, the installed and portable one works.

I'll give it a spin later today, thanks!

@danielhollas
Copy link
Collaborator

Okay, I figured out the issue with the original code and cleaned up and expanded the tests.
Unfortunately I can't push to this branch, so I opened #6866.

@agoscinski please review the second-to-last commit there with the fix. There is also some subtlety with the subclassing parameter.

@agoscinski
Copy link
Contributor

Replaced by #6866

@danielhollas
Copy link
Collaborator

@adityagh006 thank you for your work on this! 🙏
And sorry that we took over the PR, as we're trying to get this in for a release that's coming soon.

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

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

QueryBuilder can't find codes when looking for AbstractCode

3 participants