-
Notifications
You must be signed in to change notification settings - Fork 3
feat: accept str|enum region/runtime, omit when unset for org default #57
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,27 @@ | ||
| import logging | ||
| from typing import Optional | ||
| from typing import Optional, Union | ||
|
|
||
| from wherobots.db import Region | ||
| from wherobots.db.constants import DEFAULT_REGION | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| def warn_for_default_region(region: Optional[Region]) -> Region: | ||
| def warn_for_default_region( | ||
| region: Optional[Union[str, Region]], | ||
| ) -> Optional[Union[str, Region]]: | ||
| """Resolve the region argument for a Wherobots operator. | ||
|
|
||
| The value is returned unchanged — a ``Region`` enum or a raw string (e.g. a | ||
| BYOC region). Normalization (enum -> value) happens at the request boundary | ||
| (``WherobotsRestAPIHook.create_run`` / ``wherobots.db.connect``), so the enum | ||
| keeps working with older ``wherobots-python-dbapi`` releases. When no region | ||
| is provided, returns ``None`` so the API applies the organization's | ||
| configured default region — only set ``region`` to override that default. | ||
| """ | ||
| if not region: | ||
| logger.warning(""""Parameter region was not specified, it will be required by Wherobots API in the near future, please specify it in the operator. | ||
|
ClayMav marked this conversation as resolved.
|
||
| If you don't know your Wherobots Compute Region, please contact Wherobots support.""") | ||
| logger.warning(f"Using default region: {DEFAULT_REGION.value}") | ||
| region = DEFAULT_REGION | ||
| logger.info( | ||
| "No region specified; the Wherobots API will use your organization's " | ||
| "configured default region. Pass `region` to override it." | ||
| ) | ||
| return None | ||
| return region | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| from wherobots.db import Region | ||
|
|
||
| from airflow_providers_wherobots.operators import warn_for_default_region | ||
|
|
||
|
|
||
| class TestWarnForDefaultRegion: | ||
| def test_none_returns_none(self) -> None: | ||
| # No region -> None so the API applies the organization's default. | ||
| assert warn_for_default_region(None) is None | ||
|
|
||
| def test_enum_is_passed_through_unchanged(self) -> None: | ||
| # Normalization happens at the request boundary, not here, so the enum | ||
| # still works with older dbapi releases that call region.value. | ||
| assert warn_for_default_region(Region.AWS_US_WEST_2) is Region.AWS_US_WEST_2 | ||
|
|
||
| def test_string_is_passed_through(self) -> None: | ||
| assert warn_for_default_region("byoc-acme-us-east-1") == "byoc-acme-us-east-1" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.