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

Fix an AttributeError raised when a URL is used as a species #782

Merged
merged 2 commits into from
Oct 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion dandi/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,9 @@ def extract_species(metadata):
f"Cannot interpret species field: {value}. Please "
"contact [email protected] to add your species."
)
return models.SpeciesType(identifier=value_id, name=value.capitalize())
return models.SpeciesType(
identifier=value_id, name=value.capitalize() if value is not None else None
)
else:
return ...

Expand Down
92 changes: 92 additions & 0 deletions dandi/tests/data/metadata/metadata2asset_3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
{
"id": "dandiasset:0b0a1a0b-e3ea-4cf6-be94-e02c830d54be",
"schemaKey": "Asset",
"schemaVersion": "0.4.1",
"keywords": [
"test",
"sample",
"example",
"test-case"
],
"access": [
{
"schemaKey": "AccessRequirements",
"status": "dandi:OpenAccess"
}
],
"repository": "https://dandiarchive.org/",
"wasGeneratedBy": [
{
"schemaKey": "Session",
"identifier": "XYZ789",
"name": "XYZ789",
"description": "Some test data",
"startDate": "2020-08-31T15:58:28-04:00",
"used": [
{
"schemaKey": "Equipment",
"identifier": "probe:probe04",
"name": "Ecephys Probe"
}
]
}
],
"contentSize": 69105,
"encodingFormat": "application/x-nwb",
"digest": {
"dandi:dandi-etag": "e455839e5ab2fa659861f58a423fd17f-1"
},
"path": "/test/path",
"wasDerivedFrom": [
{
"schemaKey": "BioSample",
"identifier": "cell01",
"sampleType": {
"schemaKey": "SampleType",
"name": "cell"
},
"wasDerivedFrom": [
{
"schemaKey": "BioSample",
"identifier": "slice02",
"sampleType": {
"schemaKey": "SampleType",
"name": "slice"
},
"wasDerivedFrom": [
{
"schemaKey": "BioSample",
"identifier": "tissue03",
"sampleType": {
"schemaKey": "SampleType",
"name": "tissuesample"
}
}
]
}
]
}
],
"wasAttributedTo": [
{
"schemaKey": "Participant",
"identifier": "a1b2c3",
"age": {
"unitText": "ISO-8601 duration",
"value": "P170DT12212S",
"schemaKey": "PropertyValue",
"valueReference": {"schemaKey": "PropertyValue", "value": "dandi:BirthReference"}
},
"sex": {
"schemaKey": "SexType",
"identifier": "http://purl.obolibrary.org/obo/PATO_0000384",
"name": "Male"
},
"genotype": "Typical",
"species": {
"schemaKey": "SpeciesType",
"identifier": "https://www.example.com/unicorn"
}
}
]
}
41 changes: 41 additions & 0 deletions dandi/tests/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,47 @@ def test_timedelta2duration(td, duration):
"path": "/test/path",
},
),
# Put all corner cases in this test case:
(
"metadata2asset_3.json",
{
"contentSize": 69105,
"digest": "e455839e5ab2fa659861f58a423fd17f-1",
"digest_type": "dandi_etag",
"encodingFormat": "application/x-nwb",
"experiment_description": "Experiment Description",
"experimenter": "Joe Q. Experimenter",
"id": "dandiasset:0b0a1a0b-e3ea-4cf6-be94-e02c830d54be",
"institution": "University College",
"keywords": ["test", "sample", "example", "test-case"],
"lab": "Retriever Laboratory",
"related_publications": "A Brief History of Test Cases",
"session_description": "Some test data",
"session_id": "XYZ789",
"session_start_time": "2020-08-31T15:58:28-04:00",
"age": "23 days",
"date_of_birth": "2020-03-14T12:34:56-04:00",
"genotype": "Typical",
"sex": "M",
"species": "https://www.example.com/unicorn", # Corner case
"subject_id": "a1b2c3",
"cell_id": "cell01",
"slice_id": "slice02",
"tissue_sample_id": "tissue03",
"probe_ids": "probe04",
"number_of_electrodes": 42,
"number_of_units": 6,
"nwb_version": "2.2.5",
"nd_types": [
"Device (2)",
"DynamicTable",
"ElectricalSeries",
"ElectrodeGroup",
"Subject",
],
"path": "/test/path",
},
),
],
)
def test_metadata2asset(filename, metadata):
Expand Down