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

Fix KeyError in _validate_and_extract_signature_types and Add Tests for Pydantic Actions #403

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

rajatkriplani
Copy link

@rajatkriplani rajatkriplani commented Oct 18, 2024

PR fixes a KeyError issue in _validate_and_extract_signature_types when the "state" key is missing in type hints. It also has error handling and adds unit tests.

Changes

  • Updated _validate_and_extract_signature_types to use .get()
  • Added tests for error
  • Enhanced placeholder functions with valid logic in test_burr_pydantic.py.

How I tested this

Added new tests for both error and success cases. Below are the test details:

==================================================================================== test session starts =====================================================================================
platform linux -- Python 3.12.3, pytest-8.3.3, pluggy-1.5.0
rootdir: /home/divya/Code/open_scr/burr/tests
configfile: pytest.ini
plugins: anyio-4.6.2.post1
collected 30 items                                                                                                                                                                           

test_burr_pydantic.py ................s..s...s.s.s.s                                                                                                                                   [100%]

====================================================================================== warnings summary ======================================================================================
../../../../burr/lib/python3.12/site-packages/_pytest/config/__init__.py:1441
  /home/divya/Code/burr/lib/python3.12/site-packages/_pytest/config/__init__.py:1441: PytestConfigWarning: Unknown config option: asyncio_mode
  
    self._warn_or_fail_if_strict(f"Unknown config option: {key}\n")

integrations/test_burr_pydantic.py::test_subset_model_copy_config
  /home/divya/Code/burr/lib/python3.12/site-packages/pydantic/_internal/_config.py:291: PydanticDeprecatedSince20: Support for class-based `config` is deprecated, use ConfigDict instead. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.9/migration/
    warnings.warn(DEPRECATION_MESSAGE, DeprecationWarning)

integrations/test_burr_pydantic.py::test_pydantic_action_returns_correct_results_same_io_modified_async
integrations/test_burr_pydantic.py::test_pydantic_action_returns_correct_results_different_io_modified_async
integrations/test_burr_pydantic.py::test_streaming_pydantic_action_same_io_async
integrations/test_burr_pydantic.py::test_streaming_pydantic_action_different_io_async
integrations/test_burr_pydantic.py::test_end_to_end_pydantic_async
integrations/test_burr_pydantic.py::test_end_to_end_pydantic_streaming_async
  /home/divya/Code/burr/lib/python3.12/site-packages/_pytest/python.py:148: PytestUnhandledCoroutineWarning: async def functions are not natively supported and have been skipped.
  You need to install a suitable plugin for your async framework, for example:
    - anyio
    - pytest-asyncio
    - pytest-tornasync
    - pytest-trio
    - pytest-twisted
    warnings.warn(PytestUnhandledCoroutineWarning(msg.format(nodeid)))

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
========================================================================= 24 passed, 6 skipped, 8 warnings in 1.92s ==========================================================================

Notes

ensures better debugging and avoids cryptic errors , closed #385

Checklist

  • [Yes] PR has an informative and human-readable title (this will be pulled into the release notes)
  • [Yes] Changes are limited to a single goal (no scope creep)
  • [Yes] Code passed the pre-commit check & code is left cleaner/nicer than when first encountered.
  • [Yes] Any change in functionality is tested
  • [No] New functions are documented (with a description, list of inputs, and expected output)
  • [No] Placeholder code is flagged / future TODOs are captured in comments
  • [No] Project documentation has been updated if adding/changing functionality.

Important

Fix KeyError in _validate_and_extract_signature_types and add tests for Pydantic actions.

  • Bug Fix:
    • Fix KeyError in _validate_and_extract_signature_types in pydantic.py by using .get() for "state" key.
  • Tests:
    • Add tests in test_burr_pydantic.py for _validate_and_extract_signature_types to cover missing "state" key and incorrect return types.
    • Enhance placeholder functions in test_burr_pydantic.py with valid logic for testing.

This description was created by Ellipsis for 5a91b6b. It will automatically update as commits are pushed.

Copy link

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

👍 Looks good to me! Reviewed everything up to 5a91b6b in 18 seconds

More details
  • Looked at 62 lines of code in 2 files
  • Skipped 0 files when reviewing.
  • Skipped posting 1 drafted comments based on config settings.
1. burr/integrations/pydantic.py:117
  • Draft comment:
    Consider checking if state_model is a class before using issubclass to avoid potential TypeError.
  • Reason this comment was not posted:
    Decided after close inspection that this draft comment was likely wrong and/or not actionable:
    The code change already includes a check for state_model being None or inspect.Parameter.empty, which should prevent a TypeError when using issubclass. The comment may be redundant because the code change seems to handle the potential issue. The comment does not provide strong evidence of a necessary change beyond what is already implemented.
    I might be overlooking a scenario where state_model could be a non-class type that is neither None nor inspect.Parameter.empty, which could still cause a TypeError. However, the current checks seem comprehensive for the context provided.
    The checks for None and inspect.Parameter.empty should cover the cases where state_model is not a class, as these are the likely non-class values in this context.
    The comment is likely unnecessary because the code change already addresses the potential TypeError by checking for None and inspect.Parameter.empty. The comment should be deleted.

Workflow ID: wflow_TRgRGX4yohQHltuv


You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

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.

pydantic: uninformative error
1 participant