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

Two transformation functions do not return the transformed dictionary #1311

Closed
eecavanna opened this issue Nov 8, 2023 · 3 comments · Fixed by #1312
Closed

Two transformation functions do not return the transformed dictionary #1311

eecavanna opened this issue Nov 8, 2023 · 3 comments · Fixed by #1312
Assignees
Labels
bug Something isn't working high priority jupyter X SMALL Less than 8 hours, less than 1 day

Comments

@eecavanna
Copy link
Collaborator

Summary

While running a transformation function named remove_doi_slots from within a Python notebook that imports the containing Python class from the nmdc-schema Python package on PyPI, Python raised an AttributeError exception because a value of None doesn't have an attribute named get.

Screenshot

image

Related snippets

This is where the exception was raised:

# Get dois from associated_dois
associated_dois = [entry['doi_value']
for entry in study.get('associated_dois', [])]

These two transformation functions don't return the transformed dictionary (i.e. they implicitly return None since they don't have return statements):

def process_doi(self, study: dict, doi_list: list, doi_category: str):
id_value = study['id']
for doi_updates in doi_list:
if id_value == doi_updates['id']:
new_doi = {
'doi_value': doi_updates['doi'],
'doi_category': doi_category,
'doi_provider': doi_updates['doi_prov']
}
study.setdefault('associated_dois', []).append(new_doi)
def fix_award_dois(self, study: dict):

def fix_ess_dive(self, study: dict):
"""Move ess_dive_datasets values to associated_dois slot"""
study.setdefault('associated_dois', []).extend(
{'doi_value': dataset_doi, 'doi_category': 'dataset_doi',
'doi_provider': 'ess_dive'}
for dataset_doi in study.get('ess_dive_datasets', []))
def remove_doi_slots(self, study: dict):

As a result, transformation functions "further down the pipeline" won't receive a dictionary as input.

Proposal

End each transformation function with:

return study
@eecavanna
Copy link
Collaborator Author

eecavanna commented Nov 8, 2023

As a short-term workaround, in the notebook, I ignored the return values after confirming (by reviewing their source code) all the transformation functions modify the dictionary "in place."

image

I created the following PR which contains a long-term fix: #1312

@turbomam
Copy link
Member

turbomam commented Nov 8, 2023

Thanks @eecavanna

@brynnz22 would be it be OK for me to remove myself as an assignee and just leave you?

@brynnz22
Copy link
Contributor

brynnz22 commented Nov 8, 2023

@turbomam Yes! I just approved the PR. I think you already changed it? Or @eecavanna did. Thanks for the quick fix. Sorry about this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working high priority jupyter X SMALL Less than 8 hours, less than 1 day
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

3 participants