-
Notifications
You must be signed in to change notification settings - Fork 965
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
Convert tool_shed response to unicode #1703
Conversation
Unit tests are failing because the 4 parameters are None by default. |
Yep, also this is probably not the best place to do the conversion. |
5bfa28f
to
7202618
Compare
if a_string_type is str: | ||
return unicode( a_string, 'utf-8' ) | ||
elif a_string_type is unicode: | ||
return a_string |
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 happens if a_string
is 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.
You will get an exception. I copied this function from https://github.com/galaxyproject/galaxy/blob/dev/lib/galaxy/web/framework/helpers/__init__.py#L101
I was thinking about adding a check for None
, but since this is already in use in other places in the code I was thinking to best not change its behaviour.
In fact I think the to_unicode function should be moved out from lib/galaxy/web/framework/helpers/__init__.py
... what do you think about that @nsoranzo ?
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.
It will not raise an exception, it will just return nothing.
Please also keep in mind that everything in lib/galaxy/util/
should be Python3-safe, this function is not (as spotted by py34-lint tox in TravisCI).
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.
It will not raise an exception, it will just return nothing.
ah yes, sorry, I got this mixed up.
Please also keep in mind that everything in lib/galaxy/util/ should be Python3-safe, this function is not (as spotted by py34-lint tox in TravisCI).
Thanks, I will check this.
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 about something like:
from six import text_type
def to_unicode(a_string):
if a_string is None:
return None
return text_type(a_string)
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.
Awesome, that's better than
if sys.version_info[0] > 2:
def unicode(value):
"""
Passes on value in python3, as all strings are unicode.
"""
return value
Thanks!
@galaxybot test this |
@nsoranzo the remaining failure is in https://github.com/galaxyproject/galaxy/blame/dev/lib/galaxy/tools/parameters/basic.py#L166 . |
@@ -2039,7 +2036,7 @@ def single_to_python(value): | |||
else: | |||
return app.model.context.query( app.model.HistoryDatasetAssociation ).get( int( value ) ) | |||
|
|||
if isinstance(value, str) and value.find(",") > -1: | |||
if (isinstance(value, basestring) and value.find(",") > -1): |
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.
This file is not checked for Python3 compatibility yet, but I would suggest to use six.string_types
instead of basestring
anyway (same applies for lib/galaxy/tools/test.py
).
The external parentheses are not needed.
@mvdbeek No idea about that conversion from 2007. |
…nstead of basestring or str when checking instance class.
1d9b285
to
f33ddd3
Compare
The failing test on os x is just a timeout while fetching wheels. |
I think so, but let's ping @jmchilton for confirmation. |
dev...mvdbeek:replace_basestring Looks good - is that what I am confirming? |
👍 |
I'm closing this in favour of PR #1731, which also contains the necessary unicode conversion. |
Addresses issue #1702, where strings returned from the toolshed are causing problems in sqlalchemy.
With this PR unpacked json values will be converted to unicode and downstream code that checks instance type is now using
isinstance(var, text_types)
instead ofstr
orbasestring
(which is not available in python3).