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 bool conversion Verify parameter in Tableau Hook #17125

Merged
merged 2 commits into from
Jul 21, 2021

Conversation

ciancolo
Copy link
Contributor

Hello all,
During the RC tests, I founded this bug (generated from my PR #16365). The bug is present when the user set in Extra parameter field in a Tableau Connection the parameter Verify equals to false or true. During the JSON parsing, the value is automatically read as bool, so the explicit conversion str to bool is not necessary.

[2021-07-21, 07:15:33 UTC] {taskinstance.py:1455} ERROR - Task failed with exception
Traceback (most recent call last):
  File "/opt/airflow/airflow/models/taskinstance.py", line 1182, in _run_raw_task
    self._prepare_and_execute_task_with_callbacks(context, task)
  File "/opt/airflow/airflow/models/taskinstance.py", line 1285, in _prepare_and_execute_task_with_callbacks
    result = self._execute_task(context, task_copy)
  File "/opt/airflow/airflow/models/taskinstance.py", line 1315, in _execute_task
    result = task_copy.execute(context=context)
  File "/opt/airflow/airflow/providers/tableau/operators/tableau_refresh_workbook.py", line 70, in execute
    with TableauHook(self.site_id, self.tableau_conn_id) as tableau_hook:
  File "/opt/airflow/airflow/providers/tableau/hooks/tableau.py", line 70, in __init__
    verify = bool(strtobool(verify))
  File "/usr/local/lib/python3.8/distutils/util.py", line 313, in strtobool
    val = val.lower()
AttributeError: 'bool' object has no attribute 'lower'

Code changes:

  1. Added check type before conversion for Verify parameter
  2. Added test in TableauHook tests to check this situation

Thank you

@uranusjr
Copy link
Member

Not directly related to the issue, but distutils.util.strtobool is going to be deprecated in Python 3.10, so this is probably a good time as any to remove that function call entirely and implement our own boolean parsing logic.

@ciancolo
Copy link
Contributor Author

Oh really?! I didn't know. Thank you for the hint.

I was thinking, what if we removed completely the conversion? I mean the admissible value for that Verify field with json standard are:

  • true
  • false
  • string to the cert path

If the user will use for example "False" (as string) as value to Verify, in my opinion, the Tableau Hook should use it as a string and search the certificate in the path (of course it will fail). For me, it is not necessary to convert the parameter to bool in case the user uses it in the wrong way.

What do you think?

@uranusjr
Copy link
Member

We can’t just remove functionality due to backward compatibility policy—we could deprecate it, but still need to keep the logic. So something like this is probably good enough:

verify = self.conn.extra_dejson.get('verify', True)
if isinstance(verify, number.Number):  # Also allow e.g. {"verify": 1}
    verify = bool(verify)
elif isinstance(verify, str):
    warnings.warn("blah blah parsing verify from a string is deprecated", DeprecationWarning)
    from distutils.util import strtobool
    verify = strtobool(verify)
else:
    raise TypeError(f"verify needs to be a number, not {verify!r}")

@github-actions
Copy link

The PR is likely OK to be merged with just subset of tests for default Python and Database versions without running the full matrix of tests, because it does not modify the core of Airflow. If the committers decide that the full tests matrix is needed, they will add the label 'full tests needed'. Then you should rebase to the latest main or amend the last commit of the PR, and push it with --force-with-lease.

@github-actions github-actions bot added the okay to merge It's ok to merge this PR as it does not require more tests label Jul 21, 2021
@kaxil
Copy link
Member

kaxil commented Jul 21, 2021

I am ok we do this in follow up PR too but we should definitely do it i.e replace strtobool

@eladkal
Copy link
Contributor

eladkal commented Jul 21, 2021

We can’t just remove functionality due to backward compatibility policy—we could deprecate it, but still need to keep the logic

Do we need deprecation? it was added in #16365
so probably we don't need the deprecation note

@potiuk
Copy link
Member

potiuk commented Jul 21, 2021

We can’t just remove functionality due to backward compatibility policy—we could deprecate it, but still need to keep the logic

Do we need deprecation? it was added in #16365
so probably we don't need the deprecation note

Yep. We have not released it yet. No deprecation needed.

@potiuk
Copy link
Member

potiuk commented Jul 21, 2021

I am going to release an rc2 wave of July Providers shortly.

@potiuk
Copy link
Member

potiuk commented Jul 21, 2021

Random failures. Merging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:providers okay to merge It's ok to merge this PR as it does not require more tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants