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 migrate() in metadata.py #279

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

candleindark
Copy link
Member

@candleindark candleindark commented Feb 1, 2025

This PR improves migrate() by removing bugs, making it more readable, adding argument validations, etc. Please see commit message for more details of the improvements.

@candleindark candleindark added the bug Something isn't working label Feb 1, 2025
Copy link

codecov bot commented Feb 1, 2025

Codecov Report

Attention: Patch coverage is 93.75000% with 3 lines in your changes missing coverage. Please review.

Project coverage is 92.45%. Comparing base (6fd04fb) to head (89e2cb7).
Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
dandischema/metadata.py 92.68% 3 Missing ⚠️

❗ There is a different number of reports uploaded between BASE (6fd04fb) and HEAD (89e2cb7). Click for more details.

HEAD has 511 uploads less than BASE
Flag BASE (6fd04fb) HEAD (89e2cb7)
unittests 528 17
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #279      +/-   ##
==========================================
- Coverage   97.54%   92.45%   -5.10%     
==========================================
  Files          16       16              
  Lines        1753     1775      +22     
==========================================
- Hits         1710     1641      -69     
- Misses         43      134      +91     
Flag Coverage Δ
unittests 92.45% <93.75%> (-5.10%) ⬇️

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

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@candleindark candleindark marked this pull request as ready for review February 3, 2025 07:03
@yarikoptic yarikoptic requested a review from jwodder February 3, 2025 18:44
dandischema/metadata.py Outdated Show resolved Hide resolved
dandischema/metadata.py Outdated Show resolved Hide resolved
dandischema/metadata.py Outdated Show resolved Hide resolved
dandischema/metadata.py Outdated Show resolved Hide resolved
dandischema/metadata.py Outdated Show resolved Hide resolved
dandischema/metadata.py Outdated Show resolved Hide resolved
dandischema/metadata.py Show resolved Hide resolved
dandischema/metadata.py Outdated Show resolved Hide resolved
dandischema/metadata.py Outdated Show resolved Hide resolved
@yarikoptic
Copy link
Member

note that tests are failing ATM, e.g.

________ test_migrate_value_errors[obj5-0.4.5-Current target schemas:] _________
dandischema/tests/test_metadata.py:383: in test_migrate_value_errors
    migrate(obj, to_version=target, skip_validation=True)
dandischema/metadata.py:344: in migrate
    raise ValueError(msg)
E   ValueError: Target version, '0.4.5', is not a supported target schemas, ['0.6.9']

During handling of the above exception, another exception occurred:
dandischema/tests/test_metadata.py:382: in test_migrate_value_errors
    with pytest.raises(ValueError, match=msg):
E   AssertionError: Regex pattern did not match.
E    Regex: 'Current target schemas:'
E    Input: "Target version, '0.4.5', is not a supported target schemas, ['0.6.9']"

@candleindark
Copy link
Member Author

@yarikoptic Tests are updated. I think this PR is ready to be merged once you are OK with it.

Copy link
Member

@yarikoptic yarikoptic left a comment

Choose a reason for hiding this comment

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

make a bit more consistent

dandischema/metadata.py Outdated Show resolved Hide resolved
dandischema/metadata.py Outdated Show resolved Hide resolved
dandischema/metadata.py Outdated Show resolved Hide resolved
obj["schemaKey"] = "Dandiset"
obj["schemaVersion"] = to_version
return obj
if "schemaKey" not in instance_migrated["assetsSummary"]:
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if "schemaKey" not in instance_migrated["assetsSummary"]:
if "schemaKey" not in instance_migrated.get("assetsSummary", {}):

Copy link
Member Author

Choose a reason for hiding this comment

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

I replaced the line with the following instead.

        if (
            "assetsSummary" in obj_migrated
            and "schemaKey" not in obj_migrated["assetsSummary"]
        ):

@candleindark candleindark force-pushed the enh-migrate branch 2 times, most recently from 3a4ebdc to d0baff5 Compare February 6, 2025 07:57
This commit improves `migrate()` by removing bugs, making it
more readable, adding argument validations, etc. However,
it doesn't change the migration of metadata instances this
function currently intend to implement, per my best guess.
The following are descriptions of the more prominent
improvements:

1. Correct the type annotation of `to_version` (Bug fix)
2. Validate that the provided metadata instance and the
   target version specifies valid DANDI schema versions
3. Ensure the optional validation of the provided instance
   against its specified schema is done before any migration
   operation, to achieve greater consistency.
4. Return the instance unchanged when DANDI schema version
   of the given instance is equal to the target version instead
   (Bug fix).
5. Consistently use the tuple representations of DANDI schema
   versions to route the execution flow of migration operations
   to ensure all cases of the relation between the schema version
   of the instance and target version are covered.
6. Condition the migration to "0.6.0" and beyond on the target
   version being at least "0.6.0". (Bug fix)
7. Copy input instance for migration only immediately before
   migration operations
7. Rename local variables to improve readability
8. Handle the situation in which the input metadata instance not
   having the "assetsSummary" field

Co-authored-by: Yaroslav Halchenko <[email protected]>
Co-authored-by: John T. Wodder II <[email protected]>
@candleindark
Copy link
Member Author

candleindark commented Feb 6, 2025

@yarikoptic All the issues have been handled. Please do a final check and merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants