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

Print warning to stdout on load_profile for development versions #5311

Merged

Conversation

sphuber
Copy link
Contributor

@sphuber sphuber commented Jan 13, 2022

Fixes #5290

The load_profile method now calls a check_version function. This
checks what version of aiida-core is currently installed and if it is
a post release development version, a warning is printed that it should
not be run with production databases. The reason is that we cannot
support automatic data migrations for anything other than released
versions (alpha, beta, and pre-releases are supported).

This function relies on the protocol that development branches will
always use a proper post release development version defined in the
__version__ attribute of the init file of the aiida module. This
means it should be of the form 2.0.0.post0.

The choice to place the check of the version in load_profile is based
on two requirements:

  • It should be guaranteed to run however the database can be loaded
  • It should ideally only run once and not spam stdout multiple times

The load_profile function is the only way to load a profile which is
a necessary step to load any database, therefore this should guarantee
that the version check is always called when it is needed. Another
location could have been Manager._load_backend which is also
guaranteed to be called before a database is loaded, however, the
downside here is that this can be called multiple times. this would lead
to the warning being spammed multiple times.

Copy link
Member

@chrisjsewell chrisjsewell left a comment

Choose a reason for hiding this comment

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

There should be a configuration option, to turn this off for users that know what they are doing

version = parse(__version__)

if version.is_postrelease:
echo.echo_warning(f'You are currently using a post release development version of AiiDA: {version}')
Copy link
Member

Choose a reason for hiding this comment

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

This should use logger warnings, rather than using click outside of the CLI

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It does use the logging system though. It is true that the module is in the aiida.cmdline module, but after the recent refactor, they all go through the logger.

@sphuber
Copy link
Contributor Author

sphuber commented Jan 13, 2022

There should be a configuration option, to turn this off for users that know what they are doing

I agree, but last time I discussed this, @giovannipizzi had reservations about this. I am happy to implement it, but before I do, I would like consensus that we want this. So let's first get opinions from the rest.

@codecov
Copy link

codecov bot commented Jan 13, 2022

Codecov Report

Merging #5311 (ad3e217) into develop (9d2b0ac) will decrease coverage by 0.11%.
The diff coverage is 100.00%.

❗ Current head ad3e217 differs from pull request most recent head 25fe544. Consider uploading reports for the commit 25fe544 to get more accurate results
Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #5311      +/-   ##
===========================================
- Coverage    82.01%   81.91%   -0.10%     
===========================================
  Files          533      530       -3     
  Lines        38243    38019     -224     
===========================================
- Hits         31363    31140     -223     
+ Misses        6880     6879       -1     
Flag Coverage Δ
django 77.48% <100.00%> (+0.42%) ⬆️
sqlalchemy 76.22% <100.00%> (-0.13%) ⬇️

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

Impacted Files Coverage Δ
aiida/manage/configuration/__init__.py 81.09% <100.00%> (+1.88%) ⬆️
aiida/backends/sqlalchemy/models/computer.py 88.89% <0.00%> (-0.76%) ⬇️
aiida/backends/sqlalchemy/manager.py 84.91% <0.00%> (-0.54%) ⬇️
aiida/backends/sqlalchemy/models/user.py 94.74% <0.00%> (-0.50%) ⬇️
aiida/backends/sqlalchemy/models/node.py 82.61% <0.00%> (-0.48%) ⬇️
aiida/backends/sqlalchemy/models/authinfo.py 88.47% <0.00%> (-0.42%) ⬇️
aiida/backends/sqlalchemy/models/settings.py 82.61% <0.00%> (-0.37%) ⬇️
...implementations/sqlite/migrations/legacy_to_new.py 96.36% <0.00%> (-0.31%) ⬇️
aiida/backends/sqlalchemy/models/log.py 96.00% <0.00%> (-0.29%) ⬇️
aiida/backends/sqlalchemy/models/comment.py 96.16% <0.00%> (-0.27%) ⬇️
... and 6 more

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 9d2b0ac...25fe544. Read the comment docs.

if version.is_postrelease:
echo.echo_warning(f'You are currently using a post release development version of AiiDA: {version}')
echo.echo_warning('Be aware that this is not recommended for production and is not officially supported.')
echo.echo_warning('Databases used with this version may not be compatible with future releases of AiiDA.\n')
Copy link
Member

Choose a reason for hiding this comment

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

Maybe say explicitly 'and you might not be able to migrate your data to a production version of AiiDA'? Or something like this?

@giovannipizzi
Copy link
Member

Regarding the configuration option: if you feel it's useful for developers, feel free to add it.
My only comment is that the message should not suggest to turn it off, otherwise everybody does it blindly. If people really care, they should e.g. find the information in the AiiDA wiki in the pages for the developers.

So, if you want to add the option (keeping the message as it is, apart from my other comment) feel free to go ahead!

@sphuber sphuber force-pushed the fix/5290/load-profile-check-version branch 2 times, most recently from cbf207f to 850fb22 Compare January 14, 2022 16:11
@sphuber
Copy link
Contributor Author

sphuber commented Jan 14, 2022

@chrisjsewell @giovannipizzi I have implemented the option with a test and updated the warning message. Should be good for final review

Copy link
Member

@chrisjsewell chrisjsewell left a comment

Choose a reason for hiding this comment

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

Ok let's see how it goes 😅

The `load_profile` method now calls a `check_version` function. This
checks what version of `aiida-core` is currently installed and if it is
a post release development version, a warning is printed that it should
not be run with production databases. The reason is that we cannot
support automatic data migrations for anything other than released
versions (alpha, beta, and pre-releases are supported).

This function relies on the protocol that development branches will
always use a proper post release development version defined in the
`__version__` attribute of the init file of the `aiida` module. This
means it should be of the form `'2.0.0.post0`.

The choice to place the check of the version in `load_profile` is based
on two requirements:

 * It should be guaranteed to run however the database can be loaded
 * It should ideally only run once and not spam stdout multiple times

The `load_profile` function is the only way to load a profile which is
a necessary step to load any database, therefore this should guarantee
that the version check is always called when it is needed. Another
location could have been `Manager._load_backend` which is also
guaranteed to be called before a database is loaded, however, the
downside here is that this can be called multiple times. this would lead
to the warning being spammed multiple times.

A configuration option `warning.development_version` is added. It is
global only and by default set to true. When set to false, the warning
will no longer be displayed.
@sphuber sphuber force-pushed the fix/5290/load-profile-check-version branch from 850fb22 to 25fe544 Compare January 17, 2022 07:52
@sphuber sphuber merged commit 18f6c9a into aiidateam:develop Jan 17, 2022
@sphuber sphuber deleted the fix/5290/load-profile-check-version branch January 17, 2022 08:21
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.

Protocol: allow load_profile to detect when a "development" version is being used
3 participants