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

Add export archive migration for Group type strings #3912

Conversation

sphuber
Copy link
Contributor

@sphuber sphuber commented Apr 8, 2020

Fixes #3908

The Group entity class is now subclassable, for which the type string
of existing entries in the database had to be changed through a
migration. Here we add the corresponding migration for existing export
archives. The only required change is to map the type string of groups.

To test this migration we use the existing export archives in the module
tests/fixtures/export/migrate. They did not contain any group entities
so export_v0.1_simple.aiida was updated first and had four groups
added, one for each of the migrated type strings. This initial archive
was then migrated to each subsequent version, step by step, using the
command verdi export migrate --version.

@sphuber sphuber requested a review from CasperWA April 8, 2020 12:42
@sphuber
Copy link
Contributor Author

sphuber commented Apr 8, 2020

@CasperWA this PR is blocked because it depends on #3882 and #3903 need to be merged first. But I wanted to already open it to discuss it. We only have to look at the last commit. The migration is relatively simple, just updating the type_string of Group entities in archives. To test this, I use the existing export archives in the tests/fixtures/export/migrate. They did not contain any group entities, so I updated v0.1 to add 4 groups, one of each currently existing type strings, and then migrated it step by step to create each archive for each version (hence my previous PR for `verdi export migrate --version 😉 ).

Question: is this sufficient, or do we need an update in the archives that are hosted in the external repository as well?

@sphuber sphuber force-pushed the fix/3908/export-migration-group-type-strings branch 3 times, most recently from 84afa7d to cd60e0c Compare April 8, 2020 14:31
@codecov
Copy link

codecov bot commented Apr 8, 2020

Codecov Report

Merging #3912 into develop will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff            @@
##           develop    #3912   +/-   ##
========================================
  Coverage    78.21%   78.22%           
========================================
  Files          460      461    +1     
  Lines        34036    34050   +14     
========================================
+ Hits         26621    26635   +14     
  Misses        7415     7415           
Flag Coverage Δ
#django 70.25% <100.00%> (+0.01%) ⬆️
#sqlalchemy 71.11% <100.00%> (+0.01%) ⬆️
Impacted Files Coverage Δ
aiida/tools/importexport/common/config.py 100.00% <100.00%> (ø)
aiida/tools/importexport/migration/v08_to_v09.py 100.00% <100.00%> (ø)

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 9a75173...08e5310. Read the comment docs.

@sphuber sphuber force-pushed the fix/3908/export-migration-group-type-strings branch 2 times, most recently from cdacd05 to d290e5a Compare April 9, 2020 09:40
@sphuber
Copy link
Contributor Author

sphuber commented Apr 9, 2020

@CasperWA do you have an idea when you could give a look at this? Because this PR is blocking the release

@CasperWA
Copy link
Contributor

CasperWA commented Apr 9, 2020

@CasperWA do you have an idea when you could give a look at this? Because this PR is blocking the release

I can see what time I can spare over Easter and get it done. Otherwise it will not be until after, I'm afraid.

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.

Cheers @sphuber.

An initial question:

  • What changed in the export_v0.X_simple.aiida archives? They shouldn't change, I believe, right?

And then, let's go through the dedicated wiki-page.
There are 3 major steps:

  1. Export/Import archive schema
    For this I see no changes to the import/export config. So all good here.

  2. Archive migrations
    This seems to also be all done.

  3. Tests

    a. Export/Import tests for changes introduced to export/import

    You may or may not choose to add a small test here (at tests/tools/importexport/orm/test_groups.py) making sure the type_string is as expected. Perhaps a quick look through the tests may also find that some may need updating?

    b. Archive migration tests

    No PR has been made for the aiida-export-migration-tests repository in order to update it to v0.9, with all that it may entail.
    Also, you should add a test_v0.8_to_newest in tests.tools.importexport.migration.text_migration:TestExportFileMigration
    And finally, you're missing a test specifically for the migration_dbgroup_type_string function.

aiida/tools/importexport/migration/v08_to_v09.py Outdated Show resolved Hide resolved
aiida/tools/importexport/migration/v08_to_v09.py Outdated Show resolved Hide resolved
tests/tools/importexport/migration/test_v08_to_v09.py Outdated Show resolved Hide resolved
tests/tools/importexport/migration/test_v08_to_v09.py Outdated Show resolved Hide resolved
tests/tools/importexport/migration/test_v08_to_v09.py Outdated Show resolved Hide resolved
@sphuber
Copy link
Contributor Author

sphuber commented Apr 11, 2020

Thanks a lot for the review @CasperWA , especially during this easter weekend.

An initial question:

* What changed in the `export_v0.X_simple.aiida` archives? They shouldn't change, I believe, right?

As explained in the commit and OP:

To test this migration we use the existing export archives in the module
tests/fixtures/export/migrate. They did not contain any group entities
so export_v0.1_simple.aiida was updated first and had four groups
added, one for each of the migrated type strings. This initial archive
was then migrated to each subsequent version, step by step, using the
command verdi export migrate --version.

So I indeed had to update them all because none of them contained any groups.

And then, let's go through the dedicated wiki-page.

Ah yes, apologies, forgot that that existed.

3. Tests
   a. Export/Import tests for changes introduced to export/import
   You may or may not choose to add a small test here (at `tests/tools/importexport/orm/test_groups.py`) making sure the `type_string` is as expected. Perhaps a quick look through the tests may also find that some may need updating?
   b. Archive migration tests
   No PR has been made for the [`aiida-export-migration-tests` repository](https://github.com/aiidateam/aiida-export-migration-tests) in order to update it to v0.9, with all that it may entail.
   Also, you should add a `test_v0.8_to_newest` in `tests.tools.importexport.migration.text_migration:TestExportFileMigration`
   And finally, you're missing a test specifically for the `migration_dbgroup_type_string` function.

This last part 3b was exactly what I was wondering. Since the changes are really minor (just a changing of the type_string) and those changes are already tested through the simple archives that are included in aiida-core itself, is it really necessary to create an additional archive on aiida-export-migration-tests?

@CasperWA
Copy link
Contributor

To test this migration we use the existing export archives in the module
tests/fixtures/export/migrate. They did not contain any group entities
so export_v0.1_simple.aiida was updated first and had four groups
added, one for each of the migrated type strings. This initial archive
was then migrated to each subsequent version, step by step, using the
command verdi export migrate --version.

Cool, thanks! 👍

3. Tests
   a. Export/Import tests for changes introduced to export/import
   You may or may not choose to add a small test here (at `tests/tools/importexport/orm/test_groups.py`) making sure the `type_string` is as expected. Perhaps a quick look through the tests may also find that some may need updating?
   b. Archive migration tests
   No PR has been made for the [`aiida-export-migration-tests` repository](https://github.com/aiidateam/aiida-export-migration-tests) in order to update it to v0.9, with all that it may entail.
   Also, you should add a `test_v0.8_to_newest` in `tests.tools.importexport.migration.text_migration:TestExportFileMigration`
   And finally, you're missing a test specifically for the `migration_dbgroup_type_string` function.

This last part 3b was exactly what I was wondering. Since the changes are really minor (just a changing of the type_string) and those changes are already tested through the simple archives that are included in aiida-core itself, is it really necessary to create an additional archive on aiida-export-migration-tests?

You can definitely argue that it's overkill.
However, I suspect that skipping a version (no matter the minority of it) will end badly for future migration testing.
I just saw that the aiida-fleur plug-in also relies on the aiida-export-migration-tests package - for testing, I assume - so skipping a version may present unknown problems (in testing), both for aiida-core and others.

In any case, I have created a PR in the external repo that you can go through. Concerning the updated archive, I have only changed the type_string of the only group that was in there and updated the metadata.json file to reflect the new version.

@CasperWA
Copy link
Contributor

You should update to aiida-export-migration-tests==0.9.0 in this PR (just released).

@sphuber
Copy link
Contributor Author

sphuber commented Apr 14, 2020

/update-requirements

@aiida-bot-app
Copy link

aiida-bot-app bot commented Apr 14, 2020

Starting 'update-requirements' workflow for this branch.

@sphuber sphuber force-pushed the fix/3908/export-migration-group-type-strings branch from ff320a9 to b5ad5bb Compare April 14, 2020 10:00
@sphuber
Copy link
Contributor Author

sphuber commented Apr 14, 2020

@CasperWA this is ready for review

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.

Much more streamlined now it seems. Cool, thanks @sphuber.
Only a single comment/consideration.

Edit: Also, you may want to make a test under tests/tools/importexport/orm/test_groups.py to make sure the type_strings are correct in the created data.json file.
Again, this is in line with my comment here, and may be overkill and a bit too specific a test?

@sphuber
Copy link
Contributor Author

sphuber commented Apr 14, 2020

Edit: Also, you may want to make a test under tests/tools/importexport/orm/test_groups.py to make sure the type_strings are correct in the created data.json file.
Again, this is in line with my comment here, and may be overkill and a bit too specific a test?

I don't think really understand why you think there should be a test of the migration function in the orm subsection. The migration functionality should be tested in the migration tests. I do agree with your other suggestion though. Even though I made sure that the test archives now contain one group of each type, that may be changed (by mistake) in the future and then it won't be tested anymore. I will add an explicit test for the function

@sphuber sphuber force-pushed the fix/3908/export-migration-group-type-strings branch from b5ad5bb to eb3d01c Compare April 14, 2020 10:57
@sphuber sphuber requested a review from CasperWA April 14, 2020 11:10
@CasperWA
Copy link
Contributor

CasperWA commented Apr 14, 2020

Edit: Also, you may want to make a test under tests/tools/importexport/orm/test_groups.py to make sure the type_strings are correct in the created data.json file.
Again, this is in line with my comment here, and may be overkill and a bit too specific a test?

I don't think really understand why you think there should be a test of the migration function in the orm subsection. The migration functionality should be tested in the migration tests. (...)

It is in the importexport orm subsection. And it's not to test the migration, but to test that the export function is writing the correct data for Groups. But again, it may be overkill, as it would suggest we should check this for all the itty-bitty details of Node database column values, which is overkill, I think.

@sphuber
Copy link
Contributor Author

sphuber commented Apr 14, 2020

It is in the importexport orm subsection. And it's not to test the migration, but to test that the export function is writing the correct data for Groups.

I see, except this code has not been touched nor changed, so don't think we should add a test

@sphuber
Copy link
Contributor Author

sphuber commented Apr 14, 2020

@CasperWA this is ready for review

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 for the extra test @sphuber !

It said the export_v0.9_simple.aiida also changed in the latest commit, did you add or change something?

In any case, I'll approve this PR in its current state. The extra and extremely specific test under importexport/orm/test_groups.py that we have discussed is still open for you to do, but I do not consider it essential, as we should already have simple tests that makes sure we can export and import Groups, which is enough for me, and can be argued is enough for making sure the type_strings are valid, right?

@CasperWA
Copy link
Contributor

It is in the importexport orm subsection. And it's not to test the migration, but to test that the export function is writing the correct data for Groups.

I see, except this code has not been touched nor changed, so don't think we should add a test

No, it is very implicit indeed. I've accepted the PR on the basis of the current changes, but left this open for you to decide upon yourself. I consider it good enough.

@sphuber
Copy link
Contributor Author

sphuber commented Apr 14, 2020

Thanks for the review @CasperWA . I hold off a bit with merging still because technically the tests failed, but that is due to a non-related issue. The pgsu package still is not available on conda. If this won't be resolved today, I will temporarily disable those tests until it is fixed.

In any case, I'll approve this PR in its current state. The extra and extremely specific test under importexport/orm/test_groups.py that we have discussed is still open for you to do, but I do not consider it essential, as we should already have simple tests that makes sure we can export and import Groups, which is enough for me, and can be argued is enough for making sure the type_strings are valid, right?

The type_string is literally stored as a column on the DbGroup table. There is no logic between getting that value to storing it in the export file. Like all other properties of entities, this is a one-to-one dump, so it would really be overkill to test this. That would be like testing that a pk or UUID is exported correctly

The `Group` entity class is now subclassable, for which the type string
of existing entries in the database had to be changed through a
migration. Here we add the corresponding migration for existing export
archives. The only required change is to map the type string of groups.

To test this migration we use the existing export archives in the module
`tests/fixtures/export/migrate`. They did not contain any group entities
so `export_v0.1_simple.aiida` was updated first and had four groups
added, one for each of the migrated type strings. This initial archive
was then migrated to each subsequent version, step by step, using the
command `verdi export migrate --version`.

Also fixed and migrated `tests/fixtures/graphs/graph1.aiida` which was
corrupt and could not be migrated automatically, because it contained a
process node with an active process state.
@sphuber sphuber force-pushed the fix/3908/export-migration-group-type-strings branch from eb3d01c to 08e5310 Compare April 14, 2020 11:55
@CasperWA
Copy link
Contributor

In any case, I'll approve this PR in its current state. The extra and extremely specific test under importexport/orm/test_groups.py that we have discussed is still open for you to do, but I do not consider it essential, as we should already have simple tests that makes sure we can export and import Groups, which is enough for me, and can be argued is enough for making sure the type_strings are valid, right?

The type_string is literally stored as a column on the DbGroup table. There is no logic between getting that value to storing it in the export file. Like all other properties of entities, this is a one-to-one dump, so it would really be overkill to test this. That would be like testing that a pk or UUID is exported correctly

This was my understanding and thought as well, concerning the "overkill". Great to have it confirmed.

@sphuber sphuber merged commit e2c28ce into aiidateam:develop Apr 14, 2020
@sphuber sphuber deleted the fix/3908/export-migration-group-type-strings branch April 14, 2020 12:19
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.

Add migration for export archives to account for change in group type strings
2 participants