Skip to content

Commit

Permalink
BF: do or to "" to ensure that we do not end up treating None as str (#…
Browse files Browse the repository at this point in the history
…433)

* BF: do or to "" to ensure that we do not end up treating None as str

We started to get a test in dandi-cli to error out

E     +     '"/opt/hostedtoolcache/Python/3.12.1/x64/lib/python3.12/site-packages/nwbinspector/nwbinspector.py", '
E     +     'line 632, in _intercept_in_vitro_protein\n'
E     +     '    and getattr(subject, "subject_id", "").startswith("protein")\n'
E     +     '        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n'
E     +     "AttributeError: 'NoneType' object has no attribute 'startswith'\n",

I didn't test yet but this I think should fix it

* Update CHANGELOG.md

* add test

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: Cody Baker <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Feb 2, 2024
1 parent b882d36 commit 953198c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Upcoming

# v0.4.33

### Fixes

* Add safer retrieval of `subject_id` for _in vitro_ protein filtering. [#433](https://github.com/NeurodataWithoutBorders/nwbinspector/pull/433)



# v0.4.32
Expand Down
2 changes: 1 addition & 1 deletion src/nwbinspector/nwbinspector.py
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ def _intercept_in_vitro_protein(nwbfile_object: pynwb.NWBFile, checks: Optional[
if (
any(subject_related_dandi_requirements)
and subject is not None
and getattr(subject, "subject_id", "").startswith("protein")
and (getattr(subject, "subject_id") or "").startswith("protein")
):
non_subject_checks = [check for check in checks if check.__name__ not in subject_related_check_names]
return non_subject_checks
Expand Down
9 changes: 9 additions & 0 deletions tests/test_inspector.py
Original file line number Diff line number Diff line change
Expand Up @@ -740,3 +740,12 @@ def test_dandi_config_in_vitro_injection():
inspect_nwbfile_object(nwbfile_object=nwbfile, config=config, importance_threshold=importance_threshold)
)
assert messages == []


def test_dandi_config_in_vitro_injection():
"""Test the safe subject ID retrieval of the in vitro injection."""
nwbfile = make_minimal_nwbfile()
nwbfile.subject = Subject(subject_id=None, description="A detailed description about the in vitro setup.")
config = load_config(filepath_or_keyword="dandi")
messages = list(inspect_nwbfile_object(nwbfile_object=nwbfile, config=config))
assert len(messages) != 0

0 comments on commit 953198c

Please sign in to comment.