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

Fix vault plugin #4705

Merged
merged 3 commits into from
Nov 20, 2023
Merged

Fix vault plugin #4705

merged 3 commits into from
Nov 20, 2023

Conversation

pinmarva
Copy link
Contributor

The vault plugin causes the application crashes when trying to get plugins:

ERROR in app: Exception on /api/1/plugins [GET]
Traceback (most recent call last):
  File "/opt/venv/lib/python3.8/site-packages/flask/app.py", line 1484, in full_dispatch_request
    rv = self.dispatch_request()
  File "/opt/venv/lib/python3.8/site-packages/flask/app.py", line 1469, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
  File "/opt/venv/lib/python3.8/site-packages/flask_restful/__init__.py", line 493, in wrapper
    return self.make_response(data, code, headers=headers)
  File "/opt/venv/lib/python3.8/site-packages/flask_restful/__init__.py", line 522, in make_response
    resp = self.representations[mediatype](data, *args, **kwargs)
  File "/opt/venv/lib/python3.8/site-packages/flask_restful/representations/json.py", line 21, in output_json
    dumped = dumps(data, **settings) + "\n"
  File "/usr/lib/python3.8/json/__init__.py", line 231, in dumps
    return _default_encoder.encode(obj)
  File "/usr/lib/python3.8/json/encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/usr/lib/python3.8/json/encoder.py", line 257, in iterencode
    return _iterencode(o, 0)
  File "/usr/lib/python3.8/json/encoder.py", line 179, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type function is not JSON serializable
Exception on /api/1/plugins [GET]
Traceback (most recent call last):
  File "/opt/venv/lib/python3.8/site-packages/flask/app.py", line 1484, in full_dispatch_request
    rv = self.dispatch_request()
  File "/opt/venv/lib/python3.8/site-packages/flask/app.py", line 1469, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
  File "/opt/venv/lib/python3.8/site-packages/flask_restful/__init__.py", line 493, in wrapper
    return self.make_response(data, code, headers=headers)
  File "/opt/venv/lib/python3.8/site-packages/flask_restful/__init__.py", line 522, in make_response
    resp = self.representations[mediatype](data, *args, **kwargs)
  File "/opt/venv/lib/python3.8/site-packages/flask_restful/representations/json.py", line 21, in output_json
    dumped = dumps(data, **settings) + "\n"
  File "/usr/lib/python3.8/json/__init__.py", line 231, in dumps
    return _default_encoder.encode(obj)
  File "/usr/lib/python3.8/json/encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/usr/lib/python3.8/json/encoder.py", line 257, in iterencode
    return _iterencode(o, 0)
  File "/usr/lib/python3.8/json/encoder.py", line 179, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type function is not JSON serializable
Exception on /api/1/plugins [GET]
Traceback (most recent call last):
  File "/opt/venv/lib/python3.8/site-packages/flask/app.py", line 1484, in full_dispatch_request
    rv = self.dispatch_request()
  File "/opt/venv/lib/python3.8/site-packages/flask/app.py", line 1469, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
  File "/opt/venv/lib/python3.8/site-packages/flask_restful/__init__.py", line 493, in wrapper
    return self.make_response(data, code, headers=headers)
  File "/opt/venv/lib/python3.8/site-packages/flask_restful/__init__.py", line 522, in make_response
    resp = self.representations[mediatype](data, *args, **kwargs)
  File "/opt/venv/lib/python3.8/site-packages/flask_restful/representations/json.py", line 21, in output_json
    dumped = dumps(data, **settings) + "\n"
  File "/usr/lib/python3.8/json/__init__.py", line 231, in dumps
    return _default_encoder.encode(obj)
  File "/usr/lib/python3.8/json/encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/usr/lib/python3.8/json/encoder.py", line 257, in iterencode
    return _iterencode(o, 0)
  File "/usr/lib/python3.8/json/encoder.py", line 179, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type function is not JSON serializable

The problem is the function "from validators.url import url":
'url' returns "True" when validation is successful, and returns "ValidationError(func=url, args={'value': 'whatever'})" when url validation fails.
In the PR, the return of the function "url" is converted to boolean.

@jmcrawford45
Copy link
Contributor

Thank you for putting together a fix for this. Could you add a unit test which fails on main currently demonstrating this issue and that the fix addresses it?

@coveralls
Copy link

coveralls commented Nov 15, 2023

Coverage Status

coverage: 75.289% (-0.2%) from 75.446%
when pulling 10961ff on pinmarva:fix_vault_plugin
into b889412 on Netflix:main.

@pinmarva
Copy link
Contributor Author

Added the requested tests.

@jmcrawford45 jmcrawford45 merged commit 4f2d543 into Netflix:main Nov 20, 2023
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants