-
Notifications
You must be signed in to change notification settings - Fork 307
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
Prevent register_launch_plan from re-registering already registered workflow #3049
Merged
Merged
Changes from all commits
Commits
Show all changes
4 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 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 | ||||
---|---|---|---|---|---|---|
|
@@ -870,7 +870,12 @@ async def _serialize_and_register( | |||||
loop.run_in_executor( | ||||||
None, | ||||||
functools.partial( | ||||||
self.raw_register, cp_entity, serialization_settings, version, og_entity=task_entity | ||||||
self.raw_register, | ||||||
cp_entity, | ||||||
serialization_settings, | ||||||
version, | ||||||
create_default_launchplan=create_default_launchplan, | ||||||
og_entity=task_entity, | ||||||
), | ||||||
) | ||||||
) | ||||||
|
@@ -1244,6 +1249,27 @@ def register_script( | |||||
return self.register_launch_plan(entity, version, project, domain, options, serialization_settings) | ||||||
raise ValueError(f"Unsupported entity type {type(entity)}") | ||||||
|
||||||
def _wf_exists( | ||||||
self, | ||||||
name: str, | ||||||
version: str, | ||||||
project: str, | ||||||
domain: str, | ||||||
) -> bool: | ||||||
"""Does the workflow with the given id components exist?""" | ||||||
workflow_id = Identifier( | ||||||
resource_type=ResourceType.WORKFLOW, | ||||||
project=project, | ||||||
domain=domain, | ||||||
name=name, | ||||||
version=version, | ||||||
) | ||||||
try: | ||||||
self.client.get_workflow(workflow_id) | ||||||
return True | ||||||
except FlyteEntityNotExistException: | ||||||
return False | ||||||
|
||||||
def register_launch_plan( | ||||||
self, | ||||||
entity: LaunchPlan, | ||||||
|
@@ -1254,14 +1280,16 @@ def register_launch_plan( | |||||
serialization_settings: typing.Optional[SerializationSettings] = None, | ||||||
) -> FlyteLaunchPlan: | ||||||
""" | ||||||
Register a given launchplan, possibly applying overrides from the provided options. | ||||||
Register a given launchplan, possibly applying overrides from the provided options. If the underlying workflow | ||||||
is not already registered, it, along with any underlying entities, will also be registered. If the underlying | ||||||
workflow does exist (with the given project/domain/version), then only the launchplan will be registered. | ||||||
|
||||||
:param entity: Launchplan to be registered | ||||||
:param version: | ||||||
:param version: Version to be registered for the launch plan, and used to check (and register) underlying wf | ||||||
:param project: Optionally provide a project, if not already provided in flyteremote constructor or a separate one | ||||||
:param domain: Optionally provide a domain, if not already provided in FlyteRemote constructor or a separate one | ||||||
:param serialization_settings: Optionally provide serialization settings, if not provided, will use the default | ||||||
:param options: | ||||||
:return: | ||||||
""" | ||||||
if serialization_settings is None: | ||||||
_, _, _, module_file = extract_task_module(entity.workflow) | ||||||
|
@@ -1271,16 +1299,35 @@ def register_launch_plan( | |||||
source_root=project_root, | ||||||
project=project or self.default_project, | ||||||
domain=domain or self.default_domain, | ||||||
version=version, | ||||||
) | ||||||
|
||||||
if self._wf_exists( | ||||||
name=entity.workflow.name, | ||||||
version=version, | ||||||
project=serialization_settings.project, | ||||||
domain=serialization_settings.domain, | ||||||
): | ||||||
# Underlying workflow, exists, only register the launch plan itself | ||||||
launch_plan_model = get_serializable( | ||||||
OrderedDict(), settings=serialization_settings, entity=entity, options=options | ||||||
) | ||||||
ident = self.raw_register( | ||||||
launch_plan_model, serialization_settings, version, create_default_launchplan=False | ||||||
) | ||||||
if ident is None: | ||||||
raise ValueError("Failed to register launch plan, identifier returned was empty...") | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider more specific exception type
Consider using a more specific exception type like Code suggestionCheck the AI-generated fix before applying
Suggested change
Code Review Run #8550a9 Is this a valid issue, or was it incorrectly flagged by the Agent?
|
||||||
else: | ||||||
# Register the launch and everything under it | ||||||
ident = run_sync( | ||||||
self._serialize_and_register, | ||||||
entity, | ||||||
serialization_settings, | ||||||
version, | ||||||
options, | ||||||
False, | ||||||
) | ||||||
|
||||||
ident = run_sync( | ||||||
self._serialize_and_register, | ||||||
entity, | ||||||
serialization_settings, | ||||||
version, | ||||||
options, | ||||||
False, | ||||||
) | ||||||
flp = self.fetch_launch_plan(ident.project, ident.domain, ident.name, ident.version) | ||||||
flp.python_interface = entity.python_interface | ||||||
return flp | ||||||
|
This file contains 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding error handling for other potential exceptions besides
FlyteEntityNotExistException
when callingget_workflow
. Network errors or other API issues could occur.Code suggestion
Code Review Run #8550a9
Is this a valid issue, or was it incorrectly flagged by the Agent?