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

On Py3, redis job cache throws TypeError bytes / str #49060

Closed
The-Loeki opened this issue Aug 10, 2018 · 6 comments

Comments

Projects
None yet
5 participants
@The-Loeki
Copy link
Contributor

commented Aug 10, 2018

Description of Issue/Question

Traceback (most recent call last):
  File "/usr/lib64/python3.6/multiprocessing/process.py", line 258, in _bootstrap
    self.run()
  File "/usr/lib/python3.6/site-packages/salt/utils/process.py", line 747, in _run
    return self._original_run()
  File "/usr/lib/python3.6/site-packages/salt/master.py", line 223, in run
    salt.daemons.masterapi.clean_old_jobs(self.opts)
  File "/usr/lib/python3.6/site-packages/salt/daemons/masterapi.py", line 174, in clean_old_jobs
    mminion.returners[fstr]()
  File "/usr/lib/python3.6/site-packages/salt/returners/redis_return.py", line 308, in clean_old_jobs
    load_key = ret_key.replace('ret:', 'load:', 1)
TypeError: a bytes-like object is required, not 'str'

There's already unicode_literals in there, so since ret_key is a bytes, the 'fix' seems

load_key = ret_key.replace(b'ret:', b'load:', 1)

Which seems odd because the default encoding for redis is already utf8?
What's the canonical way to fix this?

Versions Report

Salt Version:
           Salt: 2018.3.0-616-ge995901
 
Dependency Versions:
           cffi: 1.11.5
       cherrypy: Not Installed
       dateutil: 2.6.1
      docker-py: 3.5.0
          gitdb: Not Installed
      gitpython: Not Installed
          ioflo: Not Installed
         Jinja2: 2.10
        libgit2: 0.26.0
        libnacl: 1.6.1
       M2Crypto: 0.28.2
           Mako: Not Installed
   msgpack-pure: Not Installed
 msgpack-python: 0.5.6
   mysql-python: Not Installed
      pycparser: 2.18
       pycrypto: 2.6.1
   pycryptodome: Not Installed
         pygit2: 0.26.4
         Python: 3.6.6 (default, Jul 19 2018, 14:25:17)
   python-gnupg: Not Installed
         PyYAML: 3.13
          PyZMQ: 17.0.0
           RAET: Not Installed
          smmap: Not Installed
        timelib: Not Installed
        Tornado: 4.5.3
            ZMQ: 4.1.6
 
System Versions:
           dist: fedora 28 Twenty Eight
         locale: UTF-8
        machine: x86_64
        release: 4.17.12-200.fc28.x86_64
         system: Linux
        version: Fedora 28 Twenty Eight
@Ch3LL

This comment has been minimized.

Copy link
Contributor

commented Aug 13, 2018

ping @saltstack/team-core any insight here on @The-Loeki 's suggested fix?

@Ch3LL Ch3LL added this to the Blocked milestone Aug 13, 2018

@rallytime

This comment has been minimized.

Copy link
Contributor

commented Aug 13, 2018

@The-Loeki Does the to_bytes function work for you here in the salt.utils.stringutils?

@DmitryKuzmenko

This comment has been minimized.

Copy link
Contributor

commented Aug 13, 2018

There are 2 related redis connector construction arguments: encoding='utf-8' and decode_responses=False.
So by default redis understands unicode strings but returns binary data and we either have to operate with bytestrings or ask redis connector to decode them for us and work with unicode as we (think that we) do now.
Since Salt is completely moved to unicode I'd better like to add the decode_responses=True to the redis connector arguments. But I don't know why py-redis developers didn't enabled it by default. Maybe just for better performance measurements =), maybe the reason is deeper.
@terminalmage what do you think?

@terminalmage

This comment has been minimized.

Copy link
Contributor

commented Aug 17, 2018

I'm not sure what the reasons are either, I've never used py-redis. However, the docs don't really warn about performance (see here), so perhaps the best solution is indeed to use decode_responses=True.

@The-Loeki

This comment has been minimized.

Copy link
Contributor Author

commented Aug 18, 2018

Thanks for the insights and the option I didn't notice at all :)

@The-Loeki

This comment has been minimized.

Copy link
Contributor Author

commented Aug 20, 2018

#49190 closes the issue, thanks again for the swift & considerate input

@The-Loeki The-Loeki closed this Aug 20, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.