Skip to content

Conversation

@yarikoptic
Copy link
Member

@yarikoptic yarikoptic commented Oct 30, 2025

Summary over compatibility is in the docstring for the function in the diff. Citing current one here for shortcut:

    Compatibility here means that the server's schema version can be either

    - lower than client has, but within the same MAJOR.MINOR component of the version
      number for 0.x series, and same MAJOR version for/after 1.x series;
    - the same;
    - higher than the client has, but only if the client's schema version is listed
      among the server's `allowed_schema_versions` (as returned by the `/info` API endpoint),
      or if not there -- `dandischema.consts.ALLOWED_INPUT_SCHEMAS` is consulted.

    If neither of above, a `SchemaVersionError` is raised.

notes:

  • - the same; is the current behavior which causes us troubles.
  • with this change, if client uses more recent version, dandiset validation (I think) would fail since server would not know how to validate it. So it would need to wait for server to upgrade dandischema to match or exceed that one

And yes , it is looking into the future as for us to establish sensible behavior(s), and we might need to adjust depending on how we address

but overall point is that dandi-cli was too protective of dandi-archive which does not really care what version of metadata you feed it with. Since there is other clients etc, if we want to restrict anyhow more -- we need to do it on server side! Meanwhile -- I am relaxing very sensibly requirements on client side! This way we very much decouple back our client from server and ease migrations etc.

Extra feature could be downgrades of schema records (dandi/dandi-schema#343) but that is yet to be decided on.

Additional refs:

Here I would introduce notion of "compatible" schema and forbid upload from "incompatible".

TODO

  • check how server behaves now and if it cares at all... may be we should allow even for upload of older versions and just rely on minimal client version to guide... on the other hand -- it is easy to upgrade client/dandischema locally so cost is small but potentially with benefits. But may be we should just issue a warning if we detect some "incompatible" version and otherwise let server decide since it would be the one capable of upgrading and judging. Notes on this exploration are below in comments.

Server might need then to either wait until upgrade it becomes capable of
validating them or we might in the future to allow client to downgrade them (on
client; loselessly only) since server cannot yet handle them.

This behavior would facilitate testing of new releases of dandi-schema which now
would fail since we require 1-to-1 correspondence. See e.g.

    dandi/dandi-schema#342 (comment)
@yarikoptic yarikoptic added the patch Increment the patch version when merged label Oct 30, 2025
@codecov
Copy link

codecov bot commented Oct 30, 2025

Codecov Report

❌ Patch coverage is 88.88889% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 75.08%. Comparing base (a79fffc) to head (0a0c59c).
⚠️ Report is 7 commits behind head on master.

Files with missing lines Patch % Lines
dandi/dandiapi.py 80.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1732      +/-   ##
==========================================
- Coverage   75.11%   75.08%   -0.04%     
==========================================
  Files          84       84              
  Lines       11856    11862       +6     
==========================================
  Hits         8906     8906              
- Misses       2950     2956       +6     
Flag Coverage Δ
unittests 75.08% <88.88%> (-0.04%) ⬇️

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.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@yarikoptic
Copy link
Member Author

yarikoptic commented Oct 30, 2025

with such dirty script
#!/bin/bash

export PS4='> '
set -x
set -eu
cd "$(mktemp -d ${TMPDIR:-/tmp}/dl-XXXXXXX)"

dandiset=000029

echo "Working at $PWD"

echo -ne "Current server info: "
curl --silent -X 'GET' \
  'https://api.dandiarchive.org/api/info/' \
  -H 'accept: application/json'  | jq .

# exploring either dandi-archive cares about versions of metadata at all!

asset=356b20b7-ae80-4d42-9715-075492eb025d
name=orig

# get info since that is where blob_id is more readily accessible as well as metadata
curl --silent -X 'GET' \
  "https://api.dandiarchive.org/api/dandisets/$dandiset/versions/draft/assets/$asset/info/" \
  -H 'accept: application/json'  > $name-info.json

blob_id=$(jq .blob -r  $name-info.json)

echo -ne "Asset metadata schema: "
jq .metadata.schemaVersion $name-info.json

echo -ne "Validation status: "
curl --silent -X 'GET' \
  "https://api.dandiarchive.org/api/dandisets/$dandiset/versions/draft/assets/$asset/validation/" \
  -H 'accept: application/json'

# Let's reupload into another file with some antiquated version of schema under a new path:
jq .metadata $name-info.json \
    | jq '.schemaVersion = "0.1.0"'  \
    | sed -e 's,\(path".*\)\.nwb,\1_dup-1.nwb,g' \
> $name-newass-meta.json

# we need to specify path as key?!
new_path=$(jq -r .path $name-newass-meta.json)

echo -e "New path arg: $new_path"

cat $name-newass-meta.json \
    | jq --arg blob_id "$blob_id" --arg path "$new_path" --slurpfile metadata $name-newass-meta.json \
        '{ blob_id: $blob_id, path: $path, metadata: $metadata[0] }' \
> $name-newass-put-data.json

curl -X 'PUT' \
  "https://api.dandiarchive.org/api/dandisets/$dandiset/versions/draft/assets/$asset/"\
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -H "Authorization: token $DANDI_API_KEY" \
  -d "@$name-newass-put-data.json" > $name-newass-put-result.json

new_asset=$(jq .asset_id $name-newass-put-result.json)
# is it valid???
curl --silent -X 'GET' \
  "https://api.dandiarchive.org/api/dandisets/$dandiset/versions/draft/assets/$new_asset/validation/" \
  -H 'accept: application/json'

I discovered

"Metadata version 0.1.0 is not allowed. Allowed are: 0.4.4, 0.5.1, 0.5.2, 0.6.0, 0.6.1, 0.6.10, 0.6.2, 0.6.3, 0.6.4, 0.6.5, 0.6.6, 0.6.7, 0.6.8, 0.6.9."

so, I think , Ideally it should be a server which exposes that information since it is concerned about its behavior and it in this case where server operates with newer version of the library and client tries to upload with older!

edit: I verified that if I specify version within that set, I did get new asset validate just fine -- see this version of asset with schema 0.6.1 which is reported valid

@yarikoptic yarikoptic added the release Create a release when this pr is merged label Oct 30, 2025
@yarikoptic yarikoptic changed the title Allow for client to provide records with newer COMPATIBLE version to the server Allow for client to provide records with newer COMPATIBLE or older (upgradable) version to the server Oct 30, 2025
@yarikoptic yarikoptic changed the title Allow for client to provide records with newer COMPATIBLE or older (upgradable) version to the server Allow for client to provide records with newer COMPATIBLE or older (upgradable) version of schema to the server Oct 30, 2025
Copy link
Member

@candleindark candleindark left a comment

Choose a reason for hiding this comment

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

Let a few comments

yarikoptic and others added 2 commits October 30, 2025 19:56
…upgradable

ATM server DOES NOT CARE! So we already allow for assets being created by other clients
with outdated schema etc. They fail validation unless could be upgraded!

Changes might need to be adjusted based on the name for the /info record
field as would be decided in dandi/dandi-archive#2624
or PR to solve it
Co-authored-by: Isaac To <candleindark@users.noreply.github.com>
Running tests with --log-cli-level=WARNING shows:

    dandi/tests/test_dandiapi.py::test_check_schema_version[1.0.0-1.2.3-False-None]
    ------------------------------------------------------------------ live log call -------------------------------------------------------------------
    WARNING  dandi:dandiapi.py:710 Server uses schema version 1.0.0 older than client's 1.2.3 (dandischema library 0.11.1). Server might fail to validate such assets and you might not be able to publish this dandiset until server is upgraded. Alternatively, you may downgrade dandischema and reupload.
    PASSED
    dandi/tests/test_dandiapi.py::test_check_schema_version[1.6.7-1.7.0-False-None]
    ------------------------------------------------------------------ live log call -------------------------------------------------------------------
    WARNING  dandi:dandiapi.py:710 Server uses schema version 1.6.7 older than client's 1.7.0 (dandischema library 0.11.1). Server might fail to validate such assets and you might not be able to publish this dandiset until server is upgraded. Alternatively, you may downgrade dandischema and reupload.
    PASSED
    dandi/tests/test_dandiapi.py::test_check_schema_version[1.6.7-1.8.3-False-None]
    ------------------------------------------------------------------ live log call -------------------------------------------------------------------
    WARNING  dandi:dandiapi.py:710 Server uses schema version 1.6.7 older than client's 1.8.3 (dandischema library 0.11.1). Server might fail to validate such assets and you might not be able to publish this dandiset until server is upgraded. Alternatively, you may downgrade dandischema and reupload.
    PASSED
    dandi/tests/test_dandiapi.py::test_check_schema_version[1.6.7-2.7.0-True-Server uses older incompatible schema version 1.6.7; client supports 2.7.0] PASSED

I think it is informative enough!
@yarikoptic
Copy link
Member Author

Ok, let's begin this week with this release ;-)

@yarikoptic yarikoptic merged commit e0f94f4 into master Nov 3, 2025
41 of 42 checks passed
@yarikoptic yarikoptic deleted the rf-schema-version branch November 3, 2025 14:06
@github-actions
Copy link

github-actions bot commented Nov 3, 2025

🚀 PR was released in 0.73.1 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

patch Increment the patch version when merged release Create a release when this pr is merged released

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants