Using pick_model in conversation_reference.py - #529
Using pick_model in conversation_reference.py#529Rodrigo Brandão (rodrigobr-msft) merged 2 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Updates ConversationReference.get_continuation_activity() to use pick_model/SkipNone so the from/from_property field is omitted (unset) when user is missing, and adjusts tests accordingly.
Changes:
- Use
pick_model(Activity, ...)instead of directActivity(...)construction. - Wrap
from_propertywithSkipNone(self.user)to omit the field whenuserisNone. - Update the corresponding unit test to assert omission rather than expecting a validation error.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| tests/activity/test_conversation_reference.py | Updates behavior expectations: from should be omitted when the user is missing. |
| libraries/microsoft-agents-activity/microsoft_agents/activity/conversation_reference.py | Switches to pick_model and uses SkipNone to avoid setting from_property when user is None. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
Suppressed comments (1)
tests/activity/test_conversation_reference.py:51
_create_conversation_reference(user=None)does not actually create a reference withuser=None(the helper substitutes a default ChannelAccount whenuser is None). This makes the test setup misleading; you can call the helper without the argument and then explicitly null outconversation_reference.userfor the scenario under test.
conversation_reference = _create_conversation_reference(user=None)
This pull request refactors the way continuation activities are generated from a
ConversationReference, making the process more robust and flexible. The main changes involve using a utility function to construct the activity model, updating how the sender is handled, and adjusting the corresponding tests.Refactoring and Model Construction:
ConversationReference.get_continuation_activityto use thepick_modelutility for constructing theActivityobject, which improves maintainability and handles optional fields more gracefully.pick_modelandSkipNoneto support the new construction logic.Handling of Optional Sender (
user):from_property) so that ifuseris missing, the field is omitted from the resulting activity instead of raising a validation error.Testing Adjustments:
useris missing, the sender field is omitted rather than causing an exception, reflecting the new behavior.Type Checking Improvements:
TYPE_CHECKINGimport and conditional import ofActivityfor improved type hinting without causing circular imports. [1] [2]