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

/api/v1/study/1/samples accepts new categories #3235

Merged
merged 5 commits into from
Jan 24, 2023

Conversation

charles-cowart
Copy link
Contributor

calling PATCH on /api/v1/study/1/samples now silently accepts metadata with new categories in them when updating a sample or adding a new one. Existing samples will be assigned a null value while samples in the metadata will be assigned the value or empty string if one was not given.

calling PATCH on /api/v1/study/1/samples now silently accepts metadata
with new categories in them when updating a sample or adding a new one.
Existing samples will be assigned a null value while samples in the
metadata will be assigned the value or empty string if one was not
given.
When a PATCH includes new samples as well as existing ones, 201 should
be returned on success, rather than 200.
@charles-cowart
Copy link
Contributor Author

singlularly, the tests complete successfully, but locally as a whole 'nosetests' fails on these tests as well. It seems like an issue with setup and teardown. Will look into it tomorrow night if I have time.

Copy link
Member

@antgonza antgonza left a comment

Choose a reason for hiding this comment

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

Looks good, thank you @charles-cowart. Just some minor comments.

qiita_pet/handlers/rest/study_samples.py Outdated Show resolved Hide resolved
qiita_pet/test/rest/test_study_samples.py Outdated Show resolved Hide resolved
@antgonza
Copy link
Member

@charles-cowart, this PR has some (minor) real errors on CI.

Tests ran fine individually, but failed when ran as a whole suite
because categories and samples added for one test would affect tests
downstream.
@coveralls
Copy link

coveralls commented Jan 24, 2023

Coverage Status

coverage: 92.915% (+0.01%) from 92.903%
when pulling f34f856 on charles-cowart:new_category_support_v4
into 9ceadff on qiita-spots:dev.

Copy link
Member

@antgonza antgonza left a comment

Choose a reason for hiding this comment

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

Thank you @charles-cowart ... one more minor comment.

# 640201 is an existing sample. blank.a2 is a new sample
body = _sample_creator(['1.SKM8.640201',
'blank.a2'], categories=current)
# body['blank.a2']['DOES_NOT_EXIST'] will be '', not None.
Copy link
Member

Choose a reason for hiding this comment

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

is this True? I think is foo, no? Same for WHAT/bar ...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope. Confirmed Friday that whenever you add a new category like we're doing here, all samples mentioned in the body will have their values set to the value you explicitly define or ''. All samples NOT mentioned in the body will have their values set to None.

self.fail("Some categories do not exist in the sample "
"information", 400,
categories_not_found=sorted(unknown))
if set(data.columns) != categories and set(data.columns).issubset(

Choose a reason for hiding this comment

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

I'm not sure if this matters in practical terms, but if the intent is to fail whenever there are missing fields, I think this code would miss a situation where a sample had new fields but was also missing existing fields, since it would neither match categories, nor be a subset.

For example, if a study had fields named FOO1, FOO2, and FOO3, and we submitted a sample with FOO1, FOO2, and FOO4, it would be missing a field but wouldn't reach this failure state.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What 171 would do is catch all subsets of categories up to but not including an exact match for categories. Sample_template.update() handles the condition you mentioned.

Although now that you bring it up, after swapping .extend() and .update(), new categories could still be added successfully and the rest call would still fail on updates - leaving the system in an unexpected state after an error. I'll take a look.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Resolved. Thanks for the catch! We now test for superset and raise a 400 if False.

@antgonza
Copy link
Member

Thank you @cassidysymons and @charles-cowart !

@antgonza antgonza merged commit 74404c4 into qiita-spots:dev Jan 24, 2023
@charles-cowart charles-cowart deleted the new_category_support_v4 branch March 1, 2023 01:21
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.

None yet

4 participants