Skip to content

JsonParseNode.try_get_anything throw exception on string starting or ending with slash #353

Closed

Description

@wiget

Environment

  • Python Version: 3.12.6
  • kiota-serialization-json version: 1.3.1 - 1.3.3
  • OS: Ubuntu 22.04

Stack trace (if available)

________________________________________________________________ test_get_anything_does_work_on_single_slash _______________________________________________________________

    def test_get_anything_does_work_on_single_slash():
        parse_node = JsonParseNode("/2")
>       result = parse_node.try_get_anything("/2")

tests/unit/test_json_parse_node.py:207: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
kiota_serialization_json/json_parse_node.py:312: in try_get_anything
    datetime_obj = pendulum.parse(value)
../../.virtualenvs/kiota/lib/python3.12/site-packages/pendulum/parser.py:30: in parse
    return _parse(text, **options)
../../.virtualenvs/kiota/lib/python3.12/site-packages/pendulum/parser.py:43: in _parse
    parsed = base_parse(text, **options)
../../.virtualenvs/kiota/lib/python3.12/site-packages/pendulum/parsing/__init__.py:78: in parse
    return _normalize(_parse(text, **_options), **_options)
../../.virtualenvs/kiota/lib/python3.12/site-packages/pendulum/parsing/__init__.py:116: in _parse
    return _parse_iso8601_interval(text)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

text = '/2'

    def _parse_iso8601_interval(text: str) -> _Interval:
        if "/" not in text:
            raise ParserError("Invalid interval")
    
        first, last = text.split("/")
        start = end = duration = None
    
>       if first[0] == "P":
E       IndexError: string index out of range

../../.virtualenvs/kiota/lib/python3.12/site-packages/pendulum/parsing/__init__.py:217: IndexError

Describe the bug

Version 1.3.1 changed how JsonParseNode behaves on a string containing a single slash at the start or the end.
Before this version try_get_anything returned the input value, on 1.3.1 an exception is raised.

To Reproduce

The simple test that can be added to tests/test_json_parse_node.py

def test_get_anything_does_work_on_single_slash():
    parse_node = JsonParseNode("/2")
    result = parse_node.try_get_anything("/2")
    assert isinstance(result, str)
    assert result == "/2"

Expected behavior

Exception should not be raised and the input value should be returned.

Screenshots

Additional context

I've encountered this issue when using Microsoft Graph API via msgraph.GraphServiceClient

Activity

  1. czaroPieczaro commented on Sep 17, 2024

    @czaroPieczaro

    Also got that error. Thanks for raising it.

  2. wiget commented on Sep 17, 2024

    @wiget
    Author

    Re-tested against 1.3.2 - still failing to parse.

  3. bennetrr commented on Oct 7, 2024

    @bennetrr

    Is there any update on this issue?

    The error comes from the pendulum library, there is also an issue in their repo: python-pendulum/pendulum#506
    However, the issue is open since 4 years, and the maintainer didn't even respond to it or the attached PR.

  4. wiget commented on Oct 10, 2024

    @wiget
    Author

    I submitted the PR in pendulum to fix the bug: python-pendulum/pendulum#843

  5. svrooij commented on Jan 26, 2025

    @svrooij
    Contributor

    Vincent Biret (@baywet) this issue might be fixed now I removed the pendulum dependency

  6. baywet commented on Jan 27, 2025

    @baywet
    Member

    Thanks Stephan van Rooij (@svrooij) for the ping on this.
    Artur Frysiak (@wiget) would you mind testing again with the latest versions of Kiota python dependencies please and reporting whether you're still facing issues?
    Thanks!

  7. wiget commented on Jan 29, 2025

    @wiget
    Author

    I tested with version 1.9.0 and the issue is gone.
    Thank you!

  8. baywet commented on Jan 29, 2025

    @baywet
    Member

    Thank you for confirming! Closing.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions