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

mysql_query.run: exception on 2018.3 #48146

Closed
rmarchei opened this Issue Jun 15, 2018 · 4 comments

Comments

@rmarchei
Contributor

rmarchei commented Jun 15, 2018

Description of Issue/Question

On Salt 2018.3 running this state raises an exception (tested with salt and salt-ssh):

purge_logs:
  mysql_query.run:
    - database: mysql
    - query: "PURGE BINARY LOGS BEFORE NOW();"
    - output: None
    - connection_default_file: /etc/mysql/debian.cnf
[ERROR   ] An exception occurred in this state: Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/salt/state.py", line 1905, in call
    **cdata['kwargs'])
  File "/usr/lib/python2.7/dist-packages/salt/loader.py", line 1830, in wrapper
    return f(*args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/salt/states/mysql_query.py", line 350, in run
    salt.utils.stringutils.to_str(query_result)
  File "/usr/lib/python2.7/dist-packages/salt/utils/stringutils.py", line 93, in to_str
    raise TypeError('expected str, bytearray, or unicode')
TypeError: expected str, bytearray, or unicode

This used to work on 2017.7.

I'm currently able to reproduce it only with the query PURGE BINARY LOGS BEFORE NOW()

Running the same query via module works as expected:

# salt-call mysql.query mysql "PURGE BINARY LOGS BEFORE NOW();" connection_default_file="/etc/mysql/debian.cnf"
local:
    ----------
    query time:
        ----------
        human:
            0.8ms
        raw:
            0.00085
    rows affected:
        0

EDIT:
I've just noticed if I remove output: None from my state, everything works again as expected:

          ID: purge_logs
    Function: mysql_query.run
      Result: True
     Comment: {u'rows affected': 0L, u'query time': {u'raw': '0.00044', u'human': u'0.4ms'}}
     Started: 01:05:39.420087
    Duration: 1382.974 ms
     Changes:
              ----------
              query:
                  Executed

I didn't realize Output: None redirects the output to a file called None. So to be precise, the crashes happens when that state tries to write the output to a file (any file).
If I don't specify an output (so it's None by default), everything works

Versions Report

# salt --versions-report
Salt Version:
           Salt: 2018.3.1

Dependency Versions:
           cffi: 1.5.2
       cherrypy: 3.5.0
       dateutil: 2.4.2
      docker-py: Not Installed
          gitdb: 0.6.4
      gitpython: 1.0.1
          ioflo: Not Installed
         Jinja2: 2.8
        libgit2: 0.24.0
        libnacl: Not Installed
       M2Crypto: Not Installed
           Mako: 1.0.3
   msgpack-pure: Not Installed
 msgpack-python: 0.4.6
   mysql-python: 1.3.7
      pycparser: 2.14
       pycrypto: 2.6.1
   pycryptodome: Not Installed
         pygit2: 0.24.0
         Python: 2.7.12 (default, Dec  4 2017, 14:50:18)
   python-gnupg: 0.3.8
         PyYAML: 3.11
          PyZMQ: 15.2.0
           RAET: Not Installed
          smmap: 0.9.0
        timelib: 0.2.4
        Tornado: 4.2.1
            ZMQ: 4.1.4

System Versions:
           dist: Ubuntu 16.04 xenial
         locale: UTF-8
        machine: x86_64
        release: 4.4.0-128-generic
         system: Linux
        version: Ubuntu 16.04 xenial
@gtmanfred

This comment has been minimized.

Contributor

gtmanfred commented Jun 15, 2018

Thanks for reporting this, we will get it fixed.

Daniel

@rallytime

This comment has been minimized.

Contributor

rallytime commented Jun 15, 2018

@garethgreenaway can you fix this one up?

@rallytime

This comment has been minimized.

Contributor

rallytime commented Jun 17, 2018

@rmarchei This should be fixed in #48164. Can you give that a try?

@rmarchei

This comment has been minimized.

Contributor

rmarchei commented Jun 17, 2018

Works perfectly, thanks!

@rallytime rallytime closed this Jun 18, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment