Skip to content

MicrosoftOutlook: Validate entrypoint arguments via Pydantic#2883

Open
PierrickV wants to merge 1 commit into
developfrom
fix-microsoftoutlook-guards
Open

MicrosoftOutlook: Validate entrypoint arguments via Pydantic#2883
PierrickV wants to merge 1 commit into
developfrom
fix-microsoftoutlook-guards

Conversation

@PierrickV

@PierrickV PierrickV commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

What

Validate MicrosoftOutlook's action arguments via Pydantic v2 models before each action runs, so missing/blank required input fails immediately with a clear validation error instead of calling the Graph API with bad data.

Changes

  • user, message_idNonEmptyStr (kept as plain non-empty strings — user accepts either an opaque object ID or a UPN, and message_id is an opaque Graph identifier)

Testing

  • pytest and black pass.

@sourcery-ai

sourcery-ai Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Adds a shared required-argument validator in the Microsoft Outlook Graph action base and applies it across message actions to guard against missing/empty user and message_id entrypoint arguments, with regression tests and a patch version bump.

Sequence diagram for required argument validation in Outlook message actions

sequenceDiagram
    actor Entrypoint
    participant MicrosoftGraphActionBase
    participant DeleteMessageAction

    Entrypoint->>DeleteMessageAction: run(arguments)
    DeleteMessageAction->>MicrosoftGraphActionBase: validate_required_arguments(arguments, required_arguments)
    alt [arguments invalid]
        MicrosoftGraphActionBase-->>DeleteMessageAction: False
        DeleteMessageAction-->>Entrypoint: return None
    else [arguments valid]
        MicrosoftGraphActionBase-->>DeleteMessageAction: True
        DeleteMessageAction->>DeleteMessageAction: access arguments["user"], arguments["message_id"]
    end
Loading

File-Level Changes

Change Details Files
Introduce a shared helper to validate required entrypoint arguments in the Microsoft Graph action base and use it to short‑circuit execution when required values are missing or empty.
  • Add Any import and define validate_required_arguments on the action base to check required keys, emit error messages, and return a boolean indicating validity.
  • Update message-oriented actions’ run methods to invoke the validator for appropriate required arguments and return early when validation fails.
MicrosoftOutlook/microsoft_outlook_modules/action_base.py
MicrosoftOutlook/microsoft_outlook_modules/action_get_message.py
MicrosoftOutlook/microsoft_outlook_modules/action_delete_message.py
MicrosoftOutlook/microsoft_outlook_modules/action_forward_message.py
MicrosoftOutlook/microsoft_outlook_modules/action_update_message.py
MicrosoftOutlook/microsoft_outlook_modules/action_send_message.py
Add regression tests ensuring missing or empty user and message_id arguments result in an error, no HTTP calls, and a None result.
  • Import Mock from unittest.mock for spying on the action.error method.
  • Add parametrized tests that remove or blank out user/message_id, assert run returns None, verify error was called with the expected message, and check that no requests_mock calls were made.
MicrosoftOutlook/tests/test_actions.py
Update documentation and metadata to reflect the new guards via a patch version bump.
  • Add a 0.1.3 entry in the changelog describing the guard behavior for user and message_id.
  • Bump the manifest version from 0.1.2 to 0.1.3.
MicrosoftOutlook/CHANGELOG.md
MicrosoftOutlook/manifest.json

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot 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.

Hey - I've left some high level feedback:

  • The validate_required_arguments calls repeat the same {"user": "User", "message_id": "Message id"} mapping in multiple actions; consider extracting this into class-level constants or shared helpers per action type to reduce duplication and make future changes less error-prone.
  • The new tests for missing user and message_id are quite similar; you could merge them into a single parametrized test that takes the missing field name as a parameter to avoid repeating setup and assertions.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The `validate_required_arguments` calls repeat the same `{"user": "User", "message_id": "Message id"}` mapping in multiple actions; consider extracting this into class-level constants or shared helpers per action type to reduce duplication and make future changes less error-prone.
- The new tests for missing `user` and `message_id` are quite similar; you could merge them into a single parametrized test that takes the missing field name as a parameter to avoid repeating setup and assertions.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@PierrickV
PierrickV force-pushed the fix-microsoftoutlook-guards branch from e03c57f to 0b57c1a Compare July 10, 2026 15:17
@PierrickV

Copy link
Copy Markdown
Contributor Author

Bumped sekoia-automation-sdk to 1.23.1 and migrated all MicrosoftOutlook native Pydantic usage away from the pydantic.v1 shim. Updated files: microsoft_outlook_modules/action_get_message.py, action_delete_message.py, action_forward_message.py, action_update_message.py, action_send_message.py, models.py, plus tests/test_actions.py, pyproject.toml, poetry.lock, and CHANGELOG.md. Validation status: poetry run pytest tests -q ✅ (36 passed), poetry run mypy microsoft_outlook_modules --ignore-missing-imports ✅, poetry run black --check microsoft_outlook_modules tests ✅. The send/update from/from_ alias behavior is now explicitly covered in tests and still passes.

@PierrickV PierrickV changed the title MicrosoftOutlook: guard against missing/empty entrypoint arguments MicrosoftOutlook: Validate entrypoint arguments via Pydantic Jul 11, 2026
@PierrickV
PierrickV requested a review from a team July 11, 2026 05:38
@PierrickV

Copy link
Copy Markdown
Contributor Author

Simplified the message action argument models by replacing repeated blank-check field_validator methods with a shared NonEmptyStr Pydantic constraint in microsoft_outlook_modules.models. This keeps the same missing/blank validation behavior with less custom code.

I intentionally kept user as a non-empty string because Microsoft Graph accepts either an opaque user object ID or a UPN/email-like value, so EmailStr would wrongly reject valid object IDs. I also kept message_id as a non-empty string because Graph message IDs are opaque identifiers, not UUIDs.

I left recipient-like fields as plain strings as well: email-validator is not declared in MicrosoftOutlook/pyproject.toml, so upgrading them to EmailStr here would add a new dependency.

…ng the action

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@PierrickV
PierrickV force-pushed the fix-microsoftoutlook-guards branch from 964a2a0 to 37580aa Compare July 13, 2026 07:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant