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

'str' object has no attribute 'decode' #76

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Failure404
Copy link
Contributor

I am trying to use user caching, after setting "cache-storage=db" I am getting

File "/usr/lib/python3/dist-packages/xclib/utf8.py", line 19, in unutf8
    return u.decode('utf-8', opts)
AttributeError: 'str' object has no attribute 'decode'

It seems like the object is already decoded.
With this fix I was able to successfully enable user caching.

I am trying to use user caching, after setting "cache-storage=db" I am getting

File "/usr/lib/python3/dist-packages/xclib/utf8.py", line 19, in unutf8
    return u.decode('utf-8', opts)
AttributeError: 'str' object has no attribute 'decode'

It seems like the object is already decoded.
With this fix I was able to successfully enable user caching.
@codecov
Copy link

codecov bot commented Feb 13, 2019

Codecov Report

Merging #76 into master will decrease coverage by 0.03%.
The diff coverage is 75%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #76      +/-   ##
==========================================
- Coverage   78.01%   77.98%   -0.04%     
==========================================
  Files          18       18              
  Lines         928      931       +3     
==========================================
+ Hits          724      726       +2     
- Misses        204      205       +1
Impacted Files Coverage Δ
xclib/utf8.py 95.23% <75%> (-4.77%) ⬇️

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 6a62dbc...28d96a1. Read the comment docs.

try:
return u.decode('utf-8', opts)
except AttributeError:
pass
Copy link
Contributor

Choose a reason for hiding this comment

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

shouldn't this be return u instead?

Copy link
Contributor Author

@Failure404 Failure404 Feb 13, 2019

Choose a reason for hiding this comment

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

Probably yes,
but I am not familiar with the code and I thought there could be cases where the object is not already decoded.
If that's not the case, then return u sounds like the most logical approach :-)

@MarcelWaldvogel
Copy link
Contributor

Thanks for the PR.

This triggered me to notice that I had disabled caching some time ago. I will reenable it and try to reproduce the problem (and add a test case).

At first glance, it looks like there should be a return u instead of the pass.

Also, during the refactoring, clearly distinguishing between str and bytes helped catch quite a few bugs. So I would like to avoid having an automatic conversion in this generic routine. This function is used throughout the code, and not only for accessing the cache. Therefore, I would suggest to this in the caller's code instead.

Would you like to try this?

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.

2 participants