[BUG] can't create grants for table with escape symbols
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 15.7k
- Forks
- 5.6k
- Avg merge
- 2d 44m
- Merged PRs (30d)
- 80
Description
Description
When we try to add grants for tables like this test\_release-_-___-%.* , after apply we get the error
Setup
(Please provide relevant configs and/or SLS files (be sure to remove sensitive info. There is no general set-up of Salt.)
grant_test_salt:
mysql_grants.present:
- user: 'test_salt'
- host: '%'
- require:
- mysql_user: test_salt
- escape: False
- names:
{%- for db in ['heroesMobileLib\_%.*'] %}
- GRANT-RO-{{ db }}:
- grant: 'SELECT'
- database: '{{ db }}'
{%- endfor %}
{%- for db in ['test\_feature\_%.*',
'test\_release-_-_-%.*',
'test\_release-_-__-%.*',
'test\_release-_-___-%.*'] %}
- GRANT-ALL-{{ db }}:
- grant: 'SELECT'
- database: '{{ db }}'
{%- endfor %}
Getting error
ID: grant_test_salt
Function: mysql_grants.present
Name: GRANT-ALL-test\_release-_-___-%.*
Result: False
Comment: An exception occurred in this state: Traceback (most recent call last):
File "salt/state.py", line 2276, in call
ret = self.states[cdata["full"]](
File "salt/loader/lazy.py", line 149, in __call__
return self.loader.run(run_func, *args, **kwargs)
File "salt/loader/lazy.py", line 1228, in run
return self._last_context.run(self._run_as, _func_or_method, *args, **kwargs)
File "salt/loader/lazy.py", line 1243, in _run_as
return _func_or_method(*args, **kwargs)
File "salt/loader/lazy.py", line 1276, in wrapper
return f(*args, **kwargs)
File "/opt/saltstack/salt/run/salt/states/mysql_grants.py", line 194, in present
if __salt__["mysql.grant_add"](
File "salt/loader/lazy.py", line 149, in __call__
return self.loader.run(run_func, *args, **kwargs)
File "salt/loader/lazy.py", line 1228, in run
return self._last_context.run(self._run_as, _func_or_method, *args, **kwargs)
File "salt/loader/lazy.py", line 1243, in _run_as
return _func_or_method(*args, **kwargs)
File "/opt/saltstack/salt/run/salt/modules/mysql.py", line 2535, in grant_add
_execute(cur, qry["qry"], qry["args"])
File "/opt/saltstack/salt/run/salt/modules/mysql.py", line 671, in _execute
return cur.execute(qry, args)
File "/opt/saltstack/salt/pypath/lib/python3.9/site-packages/pymysql/cursors.py", line 151, in execute
query = self.mogrify(query, args)
File "/opt/saltstack/salt/pypath/lib/python3.9/site-packages/pymysql/cursors.py", line 129, in mogrify
query = query % self._escape_args(args, conn)
TypeError: * wants int``
Please be as specific as possible and give set-up details.
- on-prem machine
- VM (Virtualbox, KVM, etc. please specify)
- [AWS] VM running on a cloud service, please be explicit and add details
- container (Kubernetes, Docker, containerd, etc. please specify)
- or a combination, please be explicit
- jails if it is FreeBSD
- classic packaging
- onedir packaging
- used bootstrap to install
Steps to Reproduce the behavior
(Include debug logs if possible and relevant)
Expected behavior
Grants will be added
Screenshots
If applicable, add screenshots to help explain your problem.
Versions Report
Salt Version:
Salt: 3006.8
Python Version:
Python: 3.10.14 (main, Apr 3 2024, 21:30:09) [GCC 11.2.0]
Dependency Versions:
cffi: 1.14.6
cherrypy: unknown
dateutil: 2.8.1
docker-py: Not Installed
gitdb: Not Installed
gitpython: Not Installed
Jinja2: 3.1.3
libgit2: 1.3.0
looseversion: 1.0.2
M2Crypto: Not Installed
Mako: Not Installed
msgpack: 1.0.2
msgpack-pure: Not Installed
mysql-python: Not Installed
packaging: 22.0
pycparser: 2.21
pycrypto: Not Installed
pycryptodome: 3.19.1
pygit2: 1.7.0
python-gnupg: 0.4.8
PyYAML: 6.0.1
PyZMQ: 23.2.0
relenv: 0.16.0
smmap: Not Installed
timelib: 0.2.4
Tornado: 4.5.3
ZMQ: 4.3.4
System Versions:
dist: ubuntu 22.04.4 jammy
locale: utf-8
machine: x86_64
release: 6.5.0-1020-aws
system: Linux
version: Ubuntu 22.04.4 jammy
Additional context
Add any other context about the problem here.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the grant definition in the issue, then read salt/modules/mysql.py around grant_add and salt/states/mysql_grants.py around present. Trace how the database name reaches the PyMySQL query and verify that grants for the shown escaped names complete without the TypeError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- mysql, python
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100