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

[WIP][Flytekit] Add variable_map in LiteralResolver for FlyteRemote.get Error on Dataclass/Pydantic Models #3031

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

mao3267
Copy link
Contributor

@mao3267 mao3267 commented Jan 4, 2025

Tracking issue

flyteorg/flyte#6081

Why are the changes needed?

While the task input/output is represented as a dataclass or Pydantic model, using the get function to fetch the FlyteRemote execution output will fail due to the absence of the variable_map information. To address this issue, we aim to provide the input/output variable_map in LiteralResolver to address this issue.

What changes were proposed in this pull request?

  1. Add variable_map in LiteralResolver
  2. Unit Tests should be added

How was this patch tested?

TODO

Setup process

git clone https://github.com/flyteorg/flytekit.git
gh pr checkout 2933
pip install -e .

Screenshots

TODO

Check all the applicable boxes

  • I updated the documentation accordingly.
  • All new and existing tests passed.
  • All commits are signed-off.

Related PRs

flyteorg/flyte#6136

Docs link

Summary by Bito

Enhanced FlyteRemote's LiteralResolver to improve handling of dataclass and Pydantic model inputs/outputs. Implementation includes proper handling of variable map information from data response, with null checks for variable_map field to prevent access issues. The changes standardize the use of LiteralsResolver and remove redundant empty interface checks, resulting in more robust handling of complex data types.

Unit tests added: False

Estimated effort to review (1-5, lower is better): 1

@flyte-bot
Copy link
Contributor

Code Review Agent Run Status

  • Limitations and other issues: ❌ Failure - The AI Code Review Agent skipped reviewing this change because it is configured to exclude certain pull requests based on the source/target branch or the pull request status. You can change the settings here, or contact the agent instance creator at [email protected].

@flyte-bot
Copy link
Contributor

Code Review Agent Run Status

  • Limitations and other issues: ❌ Failure - The AI Code Review Agent skipped reviewing this change because it is configured to exclude certain pull requests based on the source/target branch or the pull request status. You can change the settings here, or contact the agent instance creator at [email protected].

@flyte-bot
Copy link
Contributor

flyte-bot commented Jan 17, 2025

Code Review Agent Run #6ace01

Actionable Suggestions - 1
  • flytekit/remote/remote.py - 1
    • Consider adding null check for variable_map · Line 364-365
Review Details
  • Files reviewed - 1 · Commit Range: a88827c..3a61ac9
    • flytekit/remote/remote.py
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful

AI Code Review powered by Bito Logo

@flyte-bot
Copy link
Contributor

flyte-bot commented Jan 17, 2025

Changelist by Bito

This pull request implements the following key changes.

Key Change Files Impacted
Bug Fix - Fix Dataclass/Pydantic Model Output Retrieval

remote.py - Added variable_map handling in LiteralResolver for proper dataclass/Pydantic model output processing

Comment on lines 364 to 365
vm = VariableMap.from_flyte_idl(data_response.variable_map)
return LiteralsResolver(lm.literals, vm.variables)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding null check for variable_map

Consider adding null check for data_response.variable_map before accessing it. The variable_map field might be optional and accessing it without validation could cause issues.

Code suggestion
Check the AI-generated fix before applying
Suggested change
vm = VariableMap.from_flyte_idl(data_response.variable_map)
return LiteralsResolver(lm.literals, vm.variables)
variables = {}
if data_response.HasField("variable_map"):
vm = VariableMap.from_flyte_idl(data_response.variable_map)
variables = vm.variables
return LiteralsResolver(lm.literals, variables)

Code Review Run #6ace01


Is this a valid issue, or was it incorrectly flagged by the Agent?

  • it was incorrectly flagged

@flyte-bot
Copy link
Contributor

flyte-bot commented Jan 17, 2025

Code Review Agent Run #7c00db

Actionable Suggestions - 1
  • flytekit/remote/remote.py - 1
    • Consider consolidating input/output handling logic · Line 2527-2539
Review Details
  • Files reviewed - 1 · Commit Range: 3a61ac9..6072099
    • flytekit/remote/remote.py
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful

AI Code Review powered by Bito Logo

Comment on lines 2527 to 2539
# 如果 interface.inputs 为空,则只返回 literals
if not interface.inputs:
execution._inputs = input_literal_map.literals
else:
execution._inputs = LiteralsResolver(input_literal_map.literals, interface.inputs, self.context)

if execution.is_done and not execution.error:
output_literal_map = self._get_output_literal_map(execution_data)
execution._outputs = LiteralsResolver(output_literal_map.literals, interface.outputs, self.context)
# 如果 interface.outputs 为空,则只返回 literals
if not interface.outputs:
execution._outputs = output_literal_map.literals
else:
execution._outputs = LiteralsResolver(output_literal_map.literals, interface.outputs, self.context)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider consolidating input/output handling logic

Consider consolidating the input/output handling logic to avoid code duplication. The same pattern is repeated for both inputs and outputs.

Code suggestion
Check the AI-generated fix before applying
 -        # 如果 interface.inputs 为空,则只返回 literals
 -        if not interface.inputs:
 -            execution._inputs = input_literal_map.literals
 -        else:
 -            execution._inputs = LiteralsResolver(input_literal_map.literals, interface.inputs, self.context)
 -
 -        if execution.is_done and not execution.error:
 -            output_literal_map = self._get_output_literal_map(execution_data)
 -            # 如果 interface.outputs 为空,则只返回 literals
 -            if not interface.outputs:
 -                execution._outputs = output_literal_map.literals
 -            else:
 -                execution._outputs = LiteralsResolver(output_literal_map.literals, interface.outputs, self.context)
 +        def _assign_literals(literal_map, interface_vars, target_attr):
 +            if not interface_vars:
 +                setattr(execution, target_attr, literal_map.literals)
 +            else:
 +                setattr(execution, target_attr, LiteralsResolver(literal_map.literals, interface_vars, self.context))
 +
 +        _assign_literals(input_literal_map, interface.inputs, '_inputs')
 +
 +        if execution.is_done and not execution.error:
 +            output_literal_map = self._get_output_literal_map(execution_data)
 +            _assign_literals(output_literal_map, interface.outputs, '_outputs')

Code Review Run #7c00db


Is this a valid issue, or was it incorrectly flagged by the Agent?

  • it was incorrectly flagged

@flyte-bot
Copy link
Contributor

flyte-bot commented Jan 17, 2025

Code Review Agent Run #d1b3c9

Actionable Suggestions - 0
Review Details
  • Files reviewed - 1 · Commit Range: 6072099..270105d
    • flytekit/remote/remote.py
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful

AI Code Review powered by Bito Logo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In progress
Development

Successfully merging this pull request may close these issues.

3 participants