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

Fix issue with redismod.hmset method #48433

Merged
merged 3 commits into from Jul 6, 2018

Conversation

Projects
None yet
4 participants
@discogestalt
Contributor

discogestalt commented Jul 4, 2018

redis.StrictRedis.hmset expects a dict as its second arg, not a series of keyword args.

hmset(self, name, mapping) method of redis.client.StrictRedis instance
Set key to value within hash name for each corresponding
key and value from the mapping dict.

What does this PR do?

Fixes the call to redis.StrictRedis.hmset in the redismod.hmset method

What issues does this PR fix or reference?

N/A

Previous Behavior

Calling the redismod.hmset method either from the command line or a state/orchestration would return an invalid arguments error because the fieldsvars dict would be unpacked and passed as individual args:

Passed invalid arguments: hmset() got an unexpected keyword argument 'test1'.

New Behavior

fieldsvars dict is passed as a dict, method runs successfully.

Tests written?

No

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.

Fix issue with redismod.hmset method
redis.StrictRedis.hmset expects a dict as its second arg.

hmset(self, name, mapping) method of redis.client.StrictRedis instance
    Set key to value within hash ``name`` for each corresponding
    key and value from the ``mapping`` dict

@rallytime rallytime requested review from mirceaulinic and gtmanfred Jul 5, 2018

Found another issue with redismod.hmset
When run with salt.function in an orchestration,
several private key/value pairs are passed in
addition to the requested pairs:

127.0.0.1:6379> hkeys testing
 1) "__pub_arg"
 2) "field1"
 3) "__pub_jid"
 4) "__pub_fun"
 5) "field2"
 6) "field3"
 7) "__pub_tgt"
 8) "__pub_ret"
 9) "__pub_user"
10) "__pub_master_id"
11) "__pub_tgt_type"

Updated to filter them.
redispairs = {}
for field, value in fieldsvals.iteritems():
if not field.startswith('__'):
redispairs[field] = value

This comment has been minimized.

@gtmanfred

gtmanfred Jul 5, 2018

Contributor

You don't need to do this, use salt.utils.args.clean_kwargs

return server.hmset(key, __utils__['args.clean_kwargs'](**fieldvals))

This comment has been minimized.

@discogestalt

discogestalt Jul 5, 2018

Contributor

That works in 2018.3, but I'm working from 2017.7 and salt.utils.args.clean_kwargs isn't available there...

This comment has been minimized.

@gtmanfred

gtmanfred Jul 5, 2018

Contributor

it will be in salt.utils.clean_kwargs in 2017.7, so you cannot use the utils syntax, but you should still use this builtin.

This comment has been minimized.

@discogestalt

discogestalt Jul 5, 2018

Contributor

Excellent, updating now.

@rallytime

This comment has been minimized.

Contributor

rallytime commented Jul 6, 2018

re-run all

@rallytime rallytime merged commit 6234d9b into saltstack:2017.7 Jul 6, 2018

10 of 16 checks passed

jenkins/PR/salt-pr-linode-cent7-py3 Pull Requests » Salt PR - Linode CentOS 7 - PY3 #6263 — FAILURE
Details
jenkins/PR/salt-pr-linode-ubuntu14-n Pull Requests » Salt PR - Linode Ubuntu14.04 #24191 — FAILURE
Details
jenkins/pr/py2-centos-7 The py2-centos-7 job has failed
Details
jenkins/pr/py2-ubuntu-1604 The py2-ubuntu-1604 job has failed
Details
default Build started sha1 is merged.
Details
jenkins/PR/salt-pr-rs-cent7-n Pull Requests » Salt PR - RS CentOS 7 #20316 — RUNNING
Details
WIP ready for review
Details
continuous-integration/jenkins/pr-merge This commit looks good
Details
jenkins/PR/salt-pr-clone Pull Requests » Salt PR - Clone #26475 — SUCCESS
Details
jenkins/PR/salt-pr-docs-n Pull Requests » Salt PR - Docs #18510 — SUCCESS
Details
jenkins/PR/salt-pr-linode-ubuntu16-py3 Pull Requests » Salt PR - Linode Ubuntu16.04 - PY3 #11233 — SUCCESS
Details
jenkins/PR/salt-pr-lint-n Pull Requests » Salt PR - Code Lint #23146 — SUCCESS
Details
jenkins/pr/docs The docs job has passed
Details
jenkins/pr/lint The lint job has passed
Details
jenkins/pr/py3-centos-7 The py3-centos-7 job has passed
Details
jenkins/pr/py3-ubuntu-1604 The py3-ubuntu-1604 job has passed
Details
@rallytime

This comment has been minimized.

Contributor

rallytime commented Jul 6, 2018

Thank you for contributing @discogestalt and welcome!

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