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

[2018.3] Fix to mysql cache module #48495

Merged
merged 1 commit into from Jul 10, 2018

Conversation

Projects
None yet
5 participants
@garethgreenaway
Member

garethgreenaway commented Jul 10, 2018

What does this PR do?

Ensure the query_string is a bytestring, otherwise an attempt will be made to convert the msgpack data to unicode which will result in a UnicodeDecodeError error.

What issues does this PR fix or reference?

#48342

Commits signed with GPG?

Yes

Please review Salt's Contributing Guide for best practices.

See GitHub's page on GPG signing for more information about signing commits with GPG.

Ensure the query_string is a bytestring, otherwise an attempt will be…
… made to convert the msgpack data to unicode which will result in a UnicodeDecodeError error.

@garethgreenaway garethgreenaway requested a review from saltstack/team-core as a code owner Jul 10, 2018

@salt-jenkins salt-jenkins requested a review from saltstack/team-suse Jul 10, 2018

@rallytime rallytime merged commit f9fd1a8 into saltstack:2018.3 Jul 10, 2018

9 of 16 checks passed

continuous-integration/jenkins/pr-merge This commit cannot be built
Details
default Build finished.
Details
jenkins/PR/salt-pr-linode-ubuntu14-n Pull Requests » Salt PR - Linode Ubuntu14.04 #24236 — FAILURE
Details
jenkins/PR/salt-pr-linode-ubuntu16-py3 Pull Requests » Salt PR - Linode Ubuntu16.04 - PY3 #11278 — FAILURE
Details
jenkins/pr/lint The lint job has failed
Details
jenkins/pr/py2-ubuntu-1604 The py2-ubuntu-1604 job has failed
Details
jenkins/pr/py3-ubuntu-1604 The py3-ubuntu-1604 job has failed
Details
WIP ready for review
Details
jenkins/PR/salt-pr-clone Pull Requests » Salt PR - Clone #26520 — SUCCESS
Details
jenkins/PR/salt-pr-docs-n Pull Requests » Salt PR - Docs #18554 — SUCCESS
Details
jenkins/PR/salt-pr-linode-cent7-py3 Pull Requests » Salt PR - Linode CentOS 7 - PY3 #6308 — SUCCESS
Details
jenkins/PR/salt-pr-lint-n Pull Requests » Salt PR - Code Lint #23190 — SUCCESS
Details
jenkins/PR/salt-pr-rs-cent7-n Pull Requests » Salt PR - RS CentOS 7 #20361 — SUCCESS
Details
jenkins/pr/docs The docs job has passed
Details
jenkins/pr/py2-centos-7 The py2-centos-7 job has passed
Details
jenkins/pr/py3-centos-7 The py3-centos-7 job has passed
Details
@DmitryKuzmenko

This comment has been minimized.

Contributor

DmitryKuzmenko commented Jul 16, 2018

If data contains binary data I'd better like to transform it to an SQL friendly representation like X'01FF' than just put a binary into the query.

@DmitryKuzmenko

This comment has been minimized.

Contributor

DmitryKuzmenko commented Jul 16, 2018

This could be simply done with b''.hex() like this:

query = "REPLACE INTO {0} (bank, etcd_key, data) values('{1}', '{2}', " \
    "X'{3}')".format(_table_name, bank, key, data.hex())
@jeffclay

This comment has been minimized.

jeffclay commented Jul 24, 2018

@DmitryKuzmenko
query = "REPLACE INTO {0} (bank, etcd_key, data) values('{1}', '{2}', ""X'{3}')".format(_table_name, bank, key, data.hex())

I put all of that ^^ on one line in my code for testing.
returns error:

2018-07-24 14:41:43,335 [salt.master      :1783][ERROR   ][163723] Error in function _pillar:
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/salt/master.py", line 1776, in run_func
    ret = getattr(self, func)(load)
  File "/usr/lib/python2.7/site-packages/salt/master.py", line 1487, in _pillar
    'pillar': data})
  File "/usr/lib/python2.7/site-packages/salt/cache/__init__.py", line 156, in store
    return self.modules[fun](bank, key, data, **self._kwargs)
  File "/usr/lib/python2.7/site-packages/salt/cache/mysql_cache.py", line 191, in store
    query = "REPLACE INTO {0} (bank, etcd_key, data) values('{1}', '{2}', ""X'{3}')".format(_table_name, bank, key, data.hex())
AttributeError: 'str' object has no attribute 'hex'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment