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

Use [] as default affiliation value #282

Closed
wants to merge 2 commits into from
Closed

Conversation

waxlamp
Copy link
Member

@waxlamp waxlamp commented Feb 5, 2025

This provides [] as a default value for Person.affiliation, which is typed as a list of Affiliation. The current default value of null causes problems when trying to process an empty affiliation value in the DANDI Archive meditor (see dandi/dandi-archive#2150).

Copy link

codecov bot commented Feb 5, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.48%. Comparing base (c300776) to head (d078fbe).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #282      +/-   ##
==========================================
- Coverage   97.54%   97.48%   -0.06%     
==========================================
  Files          16       16              
  Lines        1751     1751              
==========================================
- Hits         1708     1707       -1     
- Misses         43       44       +1     
Flag Coverage Δ
unittests 97.48% <100.00%> (-0.06%) ⬇️

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.

@@ -1,4 +1,4 @@
DANDI_SCHEMA_VERSION = "0.6.9"
DANDI_SCHEMA_VERSION = "0.6.10"
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 don't know if this should be 0.6.10 or 0.7.0 (not sure what the policy is for changing a default value, even if just to fix a bug). Thoughts?

Copy link
Member

Choose a reason for hiding this comment

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

I think it is most likely to be 0.6.10. @yarikoptic ?

@@ -952,7 +952,7 @@ class Person(Contributor):
json_schema_extra={"nskey": "schema"},
)
affiliation: Optional[List[Affiliation]] = Field(
None,
default=[],
Copy link
Member

@candleindark candleindark Feb 5, 2025

Choose a reason for hiding this comment

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

I am OK with the proposed change. It will be a bit inconsistent with many other similar definitions though, such as

studyTarget: Optional[List[str]] = Field(
None,
description="Objectives or specific questions of the study.",
json_schema_extra={"nskey": "dandi"},
)
.

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 think, to the extent possible, those other definitions should be updated to also use []. This is because (1) we already ran into a UX bug due to the affiliation problem I'm addressing in this PR and (2) the jsonschema spec itself recommends that default values be valid according to the schema. I asked ChatGPT about reasons not to have a valid default value and it provided some examples (none of which seem to apply to us).

Copy link
Member

Choose a reason for hiding this comment

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

I agree with you on that if we only consider the Pydantic models.

In fact, I was thinking changing affiliation: Optional[List[Affiliation]] to just affiliation: List[Affiliation], building on your proposed change, since we don't need both None and [] to indicate having no affiliation. However, doing so has at least two downsides.

  1. We will have to migrate the existing metadata
  2. There is no default value of an empty list in LinkML. We will be able to get a more precise translation of the models to LinkML if we keep the current definition.

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 don't know how to solve the LinkML issue, but I agree with your point about changing the type to List[Affiliation]. It's true that it would require a data migration, but in my experience maintaining even slightly wrong types in systems like this tends to have compounding effects into the future (in our case, one of those effects would be the crash I'm trying to fix in the meditor). If we can figure out our approach to automatic migration of metadata, that may become less painful.

But, for now, you're thinking to not make that change in order to keep the blast radius from this PR smaller, is that right?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, I agree with you but let's keep it small for now. If it is not be cause of the LinkML translation, I would suggest changing to all similar type declaration to something like List[Affiliation] already.

@waxlamp
Copy link
Member Author

waxlamp commented Feb 6, 2025

@candleindark, I see that you approved this PR (thank you for the quick turnaround) but we still have an open question about the schema version, and there's a failing coverage test. Is there anything I should do to help advance this? Will you merge this when ready, or is that up to me?

@candleindark
Copy link
Member

@waxlamp Everything looks fine for me. "All modified and coverable lines are covered by tests." I don't do merge on this repo. @yarikoptic and @satra are the ones with the final call on this repo.

@waxlamp
Copy link
Member Author

waxlamp commented Feb 7, 2025

In light of this discussion, I'll close this PR. We can revisit this later if needed.

@waxlamp waxlamp closed this Feb 7, 2025
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.

2 participants