Skip to content

Move template-field validation out of AnthropicAgentSessionOperator _…#70432

Open
bramhanandlingala wants to merge 1 commit into
apache:mainfrom
bramhanandlingala:fix/70296-2
Open

Move template-field validation out of AnthropicAgentSessionOperator _…#70432
bramhanandlingala wants to merge 1 commit into
apache:mainfrom
bramhanandlingala:fix/70296-2

Conversation

@bramhanandlingala

Copy link
Copy Markdown
Contributor

Summary

AnthropicAgentSessionOperator.__init__ validated message and outcome
before Jinja templating runs, even though both are template_fields. A
templated outcome (e.g. outcome="{{ params.outcome }}") would crash
at DAG-parse time with AttributeError: 'str' object has no attribute 'keys', before rendering ever gets a chance to resolve it to a real dict.

Fix

providers/anthropic/src/airflow/providers/anthropic/operators/agent.py:

  • __init__ now only does plain assignments.
  • The two validation checks (message/outcome mutual exclusivity, and
    outcome requiring description + rubric) moved to the top of
    execute(), after templating has run.

Testing

providers/anthropic/tests/unit/anthropic/operators/test_agent.py:

  • Updated test_requires_exactly_one_of_message_or_outcome and
    test_outcome_requires_description_and_rubric to construct the operator
    first, then assert the ValueError is raised on .execute() instead of
    at construction.
  • Added test_init_does_not_validate_message_or_outcome to lock in that
    __init__ accepts any combination without raising.

Exemption list

Removed AnthropicAgentSessionOperator's entry from
scripts/ci/prek/validate_operators_init_exemptions.txt, as required by
the burn-down rule.

Related to #70296

@shahar1 shahar1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants