Skip to content
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

👌 IMPROVE: QueryBuilder reprs (incl/ queryhelp -> as_dict) #5081

Merged
merged 19 commits into from
Aug 17, 2021

Conversation

chrisjsewell
Copy link
Member

@chrisjsewell chrisjsewell commented Aug 15, 2021

This PR principally does:

  1. Deprecates queryhelp for as_dict() and also add a from_dict classmethod

As I believe @mbercx and @CasperWA already agree, queryhelp is a very unintuitive name, and a stumbling block for many new users.

  1. Replace the __str__ outputs with a representation of as_dict() rather than the compiled SQL query (and also use this for __repr__).

Users should not need to be exposed to the SQL, this is a "dev-user" feature

  1. Add an as_sql method, for retrieving the SQL query string

This has an option to allow for both strings with the parameters inlined or external.
It also fixes #3844 and #4659 (since the SQL string is no longer generated on print, this is also less of an issue)

  1. Add analyze_query method, to run postgresql's EXPLAIN command.

  2. Some more type hinting and tests

closes #4502
closes #3844
closes #3845
closes #4659

@codecov
Copy link

codecov bot commented Aug 16, 2021

Codecov Report

Merging #5081 (06c1e60) into develop (74571a1) will increase coverage by 0.06%.
The diff coverage is 89.39%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #5081      +/-   ##
===========================================
+ Coverage    80.44%   80.50%   +0.06%     
===========================================
  Files          531      531              
  Lines        36973    37020      +47     
===========================================
+ Hits         29738    29798      +60     
+ Misses        7235     7222      -13     
Flag Coverage Δ
django 74.99% <86.73%> (+0.07%) ⬆️
sqlalchemy 73.93% <84.08%> (+0.07%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
aiida/tools/importexport/dbexport/main.py 97.31% <ø> (ø)
aiida/orm/implementation/django/querybuilder.py 78.75% <75.00%> (+0.91%) ⬆️
...iida/orm/implementation/sqlalchemy/querybuilder.py 82.03% <87.50%> (+0.99%) ⬆️
aiida/orm/querybuilder.py 83.94% <90.13%> (+2.19%) ⬆️
aiida/tools/graph/age_rules.py 89.19% <93.34%> (ø)
aiida/restapi/resources.py 97.26% <100.00%> (ø)
aiida/transports/plugins/local.py 81.41% <0.00%> (-0.25%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 74571a1...06c1e60. Read the comment docs.

@chrisjsewell
Copy link
Member Author

Ok this is done, I would like to merge this asap, to feed it up into #5069. So looking to merge in next day or two

@property
def queryhelp(self) -> QueryDict:
""""Legacy name for ``as_dict`` method."""
# deprecate?
Copy link
Member Author

Choose a reason for hiding this comment

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

The only outstanding question, for me, is whether we actually add a deprecation warning here, or "schedule" it for a later date. I guess essentially it shouldn't be removed until v3?

Copy link
Member Author

@chrisjsewell chrisjsewell Aug 16, 2021

Choose a reason for hiding this comment

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

I don't think it will be good for users to have deorecation warnings showing up when they've just switched to v2, so I would be tempted to leave it for now

Copy link
Contributor

@CasperWA CasperWA left a comment

Choose a reason for hiding this comment

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

Cool, thanks @chrisjsewell !

Some comments along with the actual review comments:
Maybe rename the awkward _kw to the more standard kwargs?
Are the *.txt and test_as_dict.yml files in the test folder for the QueryBuilder necessary? They seem to maybe be relics from some tests that should be removed or are they intentional?

aiida/orm/querybuilder.py Outdated Show resolved Hide resolved
aiida/orm/querybuilder.py Outdated Show resolved Hide resolved
aiida/orm/querybuilder.py Outdated Show resolved Hide resolved
aiida/orm/querybuilder.py Show resolved Hide resolved
aiida/orm/querybuilder.py Show resolved Hide resolved
aiida/restapi/resources.py Show resolved Hide resolved
docs/source/topics/database.rst Show resolved Hide resolved
docs/source/topics/database.rst Outdated Show resolved Hide resolved
docs/source/topics/database.rst Outdated Show resolved Hide resolved
docs/source/topics/database.rst Outdated Show resolved Hide resolved
@chrisjsewell
Copy link
Member Author

cheers for the quick review @CasperWA 😄

@chrisjsewell
Copy link
Member Author

Are the *.txt and test_as_dict.yml files in the test folder for the QueryBuilder necessary? They seem to maybe be relics from some tests that should be removed or are they intentional?

No they are intentional and generated in tests/orm/test_querybuilder.py::TestRepresentations by pytest-regressions

@chrisjsewell
Copy link
Member Author

Maybe rename the awkward _kw to the more standard kwargs?

done

Co-authored-by: Casper Welzel Andersen <43357585+CasperWA@users.noreply.github.com>
@CasperWA
Copy link
Contributor

No they are intentional and generated in tests/orm/test_querybuilder.py::TestRepresentations by pytest-regressions

Why? Is there a reason this is necessary to keep in the repo? Couldn't it just be deleted after use or kept in memory if it's to be used elsewhere?

@chrisjsewell
Copy link
Member Author

No they are intentional and generated in tests/orm/test_querybuilder.py::TestRepresentations by pytest-regressions

Why? Is there a reason this is necessary to keep in the repo? Couldn't it just be deleted after use or kept in memory if it's to be used elsewhere?

No this is just how https://pytest-regressions.readthedocs.io works; it’s regressing against the stored files. I’d definitely recommend it, we use it loads, for example, in aiida-quantumespresso

@ltalirz ltalirz removed their request for review August 16, 2021 12:58
@chrisjsewell chrisjsewell requested a review from CasperWA August 16, 2021 16:45
@chrisjsewell
Copy link
Member Author

@CasperWA I've addressed all your comments cheers

@chrisjsewell chrisjsewell changed the title 👌 IMPROVE: QueryBuilder representations (replace queryhelp) 👌 IMPROVE: QueryBuilder reprs (incl/ queryhelp -> as_dict) Aug 16, 2021
@chrisjsewell
Copy link
Member Author

chrisjsewell commented Aug 17, 2021

merging this today (the link check fail is just that https://shapeshed.com/unix-exit-codes/ is down at present)

@CasperWA
Copy link
Contributor

merging this today (the link check fail is just that https://shapeshed.com/unix-exit-codes/ is down at present)

Sure - but maybe always wait for an approving review, or?

CasperWA
CasperWA previously approved these changes Aug 17, 2021
Copy link
Contributor

@CasperWA CasperWA left a comment

Choose a reason for hiding this comment

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

Thanks a bunch @chrisjsewell !
Approved on my end. I found a single "one sentence per one line" thing in the documentation and that's about it.

docs/source/topics/database.rst Outdated Show resolved Hide resolved
@chrisjsewell
Copy link
Member Author

but maybe always wait for an approving review,

I had full faith that you would sign it off today 😄

@chrisjsewell
Copy link
Member Author

Approved on my end

Thanks!

Co-authored-by: Casper Welzel Andersen <43357585+CasperWA@users.noreply.github.com>
@chrisjsewell chrisjsewell merged commit ccd5795 into aiidateam:develop Aug 17, 2021
@chrisjsewell chrisjsewell deleted the querybuilder-repr branch August 17, 2021 09:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants