-
Notifications
You must be signed in to change notification settings - Fork 11
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
Conversation
Codecov Report
@@ Coverage Diff @@
## master #81 +/- ##
=======================================
Coverage 90.13% 90.13%
=======================================
Files 13 13
Lines 1318 1318
=======================================
Hits 1188 1188
Misses 130 130
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
@@ -153,7 +153,7 @@ def to_datacite( | |||
continue | |||
|
|||
contr_all = [] | |||
if getattr(contr_el, "roleName"): | |||
if contr_el.roleName: |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
returnsNone
, 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
)
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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
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 ;-) |
This is required to include dandi/dandi-schema#81, which fixes dandi/dandi-schema#80, which broke publish in some cases.
fixes #80