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

fixing to_datacie, allowing for None in roleName #81

Merged
merged 1 commit into from
Sep 9, 2021

Conversation

djarecka
Copy link
Member

@djarecka djarecka commented Sep 8, 2021

fixes #80

@codecov
Copy link

codecov bot commented Sep 8, 2021

Codecov Report

Merging #81 (fef797c) into master (1054377) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master      #81   +/-   ##
=======================================
  Coverage   90.13%   90.13%           
=======================================
  Files          13       13           
  Lines        1318     1318           
=======================================
  Hits         1188     1188           
  Misses        130      130           
Flag Coverage Δ
unittests 90.13% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
dandischema/tests/test_datacite.py 43.66% <ø> (ø)
dandischema/datacite.py 56.12% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1054377...fef797c. Read the comment docs.

@djarecka djarecka requested a review from yarikoptic September 9, 2021 15:32
@@ -153,7 +153,7 @@ def to_datacite(
continue

contr_all = []
if getattr(contr_el, "roleName"):
if contr_el.roleName:
Copy link
Member

Choose a reason for hiding this comment

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

what was rationale for this particular line change? getattr is safer and I might have been used for a reason (some prior version having no .roleName?) so I would have just kept this as is.

Otherwise looks good to me

Copy link
Member

Choose a reason for hiding this comment

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

getattr() raises AttributeError if the attribute doesn't exist (according to the hasattr() docs), so this change is actually better than calling getattr(), because it's a more standard expression of pulling an attribute from an object.

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've changed it only because I realize that roleName has None as default, so the attribute should always exist, but I could revert

Copy link
Member

Choose a reason for hiding this comment

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

As I mentioned, I'd keep this the way it is now, since the old and new versions have exactly the same effect, but the new version is more standard.

Copy link
Member

Choose a reason for hiding this comment

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

Thank you @waxlamp ! Indeed, this RF is ok here (although unrelated to the purpose of the PR). I guess while analyzing for it, I have also misguided myself by the fact that dict.get(key) does default to not blowing up but just returning None if key is not in the dict. May be original intention was similarly misguided in 4878d23 @djarecka but lacked that specification of the default?

Copy link
Member Author

Choose a reason for hiding this comment

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

@yarikoptic - the only reason why I've changes it here was because I was exploring the default behavior if nothing is passed as roleName (that was the example that caused an issue for you).

Copy link
Member Author

Choose a reason for hiding this comment

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

@waxlamp - yes, that's true that getattr returns None, so it's often a save check that avoids raising any exceptions. Probably that was the reason why I used it at the beginning.

Copy link
Member

Choose a reason for hiding this comment

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

@waxlamp - yes, that's true that getattr returns None, so it's often a save check that avoids raising any exceptions. Probably that was the reason why I used it at the beginning.

may be a typo (dict.get instead of getattr?) since that is the point @waxlamp mentioned above that getattr does raise exception if the default is not specified explicitly (which differs in behavior from dict.get where default does not need to be specified and defaults to None)

Copy link
Member

Choose a reason for hiding this comment

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

overall -- there is no point to use getattr(obj, "string with the fieldname") over obj.fieldname, unless providing an explicit default, as e.g. getattr(obj, "string with the fieldname", None)

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, I'm sorry. I've mixed also in the discussion getattr and dict.get. But I understand that this could stay like this

@yarikoptic
Copy link
Member

anyways , for the purpose of a fix I think we have reviewed it and there is even a test -- nothing should hold the progress. to facilitate immediate availability of the fix for dandi-api I will add 'release' label and merge. Current git describe: 0.3.2-3-g1054377 -- with the release will test new versiongit ;-)

@yarikoptic yarikoptic added release Create a release when this pr is merged patch Increment the patch version when merged labels Sep 9, 2021
@yarikoptic yarikoptic merged commit 43c5d43 into dandi:master Sep 9, 2021
dchiquito added a commit to dandi/dandi-archive that referenced this pull request Sep 9, 2021
This is required to include
dandi/dandi-schema#81, which fixes
dandi/dandi-schema#80, which broke publish in
some cases.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
patch Increment the patch version when merged release Create a release when this pr is merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

to_datacite: TypeError: argument of type 'NoneType' is not iterable
3 participants