-
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
QueryBuilder
: fix type string filter generation for Group
subclasses
#4144
QueryBuilder
: fix type string filter generation for Group
subclasses
#4144
Conversation
The `aiida.orm.querybuilder.get_group_type_filter` function that is responsible for generating the correct filters for the `type_string` when a `Group` or subclass of it is appended, contained a bug. To generate the correct type string, it should strip the `group.` prefix from the provided ORM classifier. This was incorrectly done with the string method `lstrip`, which does not strip an entire prefix as is, but will strip any characters that are matched starting from the left. This would cause extra characters to be erroneously stripped if the rest of the type string started with any letters in the sequence `group.`. For example `group.pseudo.family` would be stripped to `seudo.family`. The solution is to use the first N characters where N is the length of the prefix.
0fd0c0c
to
b7bacd5
Compare
Codecov Report
@@ Coverage Diff @@
## develop #4144 +/- ##
===========================================
+ Coverage 78.86% 78.87% +0.02%
===========================================
Files 467 467
Lines 34481 34481
===========================================
+ Hits 27189 27194 +5
+ Misses 7292 7287 -5
Continue to review full report at Codecov.
|
My only question would be if by this point in the code is it guaranteed that the string will start with that prefix and you are not just stripping part of the type away? And this is backwards compatible with older versions of this label? |
Yes, this should be guaranteed because the aiida-core/aiida/orm/querybuilder.py Line 97 in 690025e
The code is a mess overall, but it will require a lot of work to refactor it all in to something more comprehensible and less error prone.
There is no question of backwards compatibility here. This was an internal bug in the |
No, what I meant is that perhaps this was using |
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.
Saul Goodman!
It was using Thanks for the review 👍 |
That is common enough that it got its own PEP: https://www.python.org/dev/peps/pep-0616/ 😂 |
Python 3.9 here we go ! 🚀 |
Fixes #4143
The
aiida.orm.querybuilder.get_group_type_filter
function that isresponsible for generating the correct filters for the
type_string
when a
Group
or subclass of it is appended, contained a bug. Togenerate the correct type string, it should strip the
group.
prefixfrom the provided ORM classifier. This was incorrectly done with the
string method
lstrip
, which does not strip an entire prefix as is, butwill strip any characters that are matched starting from the left. This
would cause extra characters to be erroneously stripped if the rest of
the type string started with any letters in the sequence
group.
. Forexample
group.pseudo.family
would be stripped toseudo.family
. Thesolution is to use the first N characters where N is the length of the
prefix.