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

Enable detection of errors in Variable.get() such as absence of key method and connection failure to Metastore #39577

Open
2 tasks done
tyama711 opened this issue May 12, 2024 · 3 comments
Labels
kind:feature Feature Requests needs-triage label for new issues that we didn't triage yet pending-response stale Stale PRs per the .github/workflows/stale.yml policy file

Comments

@tyama711
Copy link

tyama711 commented May 12, 2024

Description

When attempting to retrieve a value by specifying a key using the Variable.get() method, there are cases where the retrieval fails, such as:

  • When the specified key does not exist in environment variables or Metastore
  • When there is a connection failure to Metastore or some other error

However, in the current implementation of Airflow, all exception handling is being suppressed in the following part, making it impossible for users to differentiate these cases:

except Exception:
log.exception(
"Unable to retrieve variable from secrets backend (%s). "
"Checking subsequent secrets backend.",
type(secrets_backend).__name__,
)

I believe that Variable.get() should return None if the specified key does not exist, and it should raise an exception for unexpected errors such as connection errors.

Use case/motivation

With this feature, it becomes possible to handle errors specific to each cause as follows:

  • When the specified key does not exist in environment variables or Metastore --> Use some default value
  • When there is a connection failure to Metastore or some other error --> Retry several times, and if unsuccessful, fail the job.

Related issues

No response

Are you willing to submit a PR?

  • Yes I am willing to submit a PR!

Code of Conduct

@tyama711 tyama711 added kind:feature Feature Requests needs-triage label for new issues that we didn't triage yet labels May 12, 2024
Copy link

boring-cyborg bot commented May 12, 2024

Thanks for opening your first issue here! Be sure to follow the issue template! If you are willing to raise PR to address this issue please do so, no need to wait for approval.

@romsharon98
Copy link
Collaborator

Hi @tyama711 thanks for opening this issue.
You can give the get function a default value if the variable is not exist.

Variable.get(key='dummy_key', default_var='default_value')

As you said you can retry for any exception you get so I don't think we need to return more specific exception, let me know what you think.

Copy link

github-actions bot commented Jun 1, 2024

This issue has been automatically marked as stale because it has been open for 14 days with no response from the author. It will be closed in next 7 days if no further activity occurs from the issue author.

@github-actions github-actions bot added the stale Stale PRs per the .github/workflows/stale.yml policy file label Jun 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:feature Feature Requests needs-triage label for new issues that we didn't triage yet pending-response stale Stale PRs per the .github/workflows/stale.yml policy file
Projects
None yet
Development

No branches or pull requests

3 participants