microsoftgraph / msgraph-sdk-python

MIT License
388 stars 56 forks source link

Exception while reading Planner entities with some orderHints #531

Closed Spaider closed 7 months ago

Spaider commented 11 months ago

There are exceptions while parsing some orderHint's for Planner Task/Task Details resources. Exception occurs in pendulum library but is not captured on msgraph level.

The following is a stack trace for one of the cases. Problem is in a trailing slash:

Stack trace for `orderHint == "8585818138483656586P/` ``` ERROR:PlannerMigration:Error reading task 7ToMjXLIl0iYcc-QlvqpqZgAIDfL details: string index out of range Traceback (most recent call last): File "/Users/admin/Projects/GitLab/its-planner-migration/its_planner_migration/PlannerMigration.py", line 195, in read_plan await self._src_graph.get_task_details(t.id) File "/Users/admin/Projects/GitLab/its-planner-migration/its_planner_migration/graph.py", line 100, in get_task_details planner_response = await self.client.planner.tasks.by_planner_task_id(task_id).details.get() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/admin/.virtualenvs/msgraph/lib/python3.11/site-packages/msgraph/generated/planner/tasks/item/details/details_request_builder.py", line 68, in get return await self.request_adapter.send_async(request_info, PlannerTaskDetails, error_mapping) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/admin/.virtualenvs/msgraph/lib/python3.11/site-packages/kiota_http/httpx_request_adapter.py", line 192, in send_async value = root_node.get_object_value(parsable_factory) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/admin/.virtualenvs/msgraph/lib/python3.11/site-packages/kiota_serialization_json/json_parse_node.py", line 212, in get_object_value self._assign_field_values(result) File "/Users/admin/.virtualenvs/msgraph/lib/python3.11/site-packages/kiota_serialization_json/json_parse_node.py", line 281, in _assign_field_values field_deserializer(JsonParseNode(field_value)) File "/Users/admin/.virtualenvs/msgraph/lib/python3.11/site-packages/msgraph/generated/models/planner_task_details.py", line 54, in "checklist": lambda n : setattr(self, 'checklist', n.get_object_value(PlannerChecklistItems)), ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/admin/.virtualenvs/msgraph/lib/python3.11/site-packages/kiota_serialization_json/json_parse_node.py", line 212, in get_object_value self._assign_field_values(result) File "/Users/admin/.virtualenvs/msgraph/lib/python3.11/site-packages/kiota_serialization_json/json_parse_node.py", line 283, in _assign_field_values item_additional_data[field_name] = self.try_get_anything(field_value) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/admin/.virtualenvs/msgraph/lib/python3.11/site-packages/kiota_serialization_json/json_parse_node.py", line 296, in try_get_anything return dict(map(lambda x: (x[0], self.try_get_anything(x[1])), value.items())) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/admin/.virtualenvs/msgraph/lib/python3.11/site-packages/kiota_serialization_json/json_parse_node.py", line 296, in return dict(map(lambda x: (x[0], self.try_get_anything(x[1])), value.items())) ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/admin/.virtualenvs/msgraph/lib/python3.11/site-packages/kiota_serialization_json/json_parse_node.py", line 299, in try_get_anything datetime_obj = pendulum.parse(value) ^^^^^^^^^^^^^^^^^^^^^ File "/Users/admin/.virtualenvs/msgraph/lib/python3.11/site-packages/pendulum/parser.py", line 29, in parse return _parse(text, **options) ^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/admin/.virtualenvs/msgraph/lib/python3.11/site-packages/pendulum/parser.py", line 45, in _parse parsed = base_parse(text, **options) ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/admin/.virtualenvs/msgraph/lib/python3.11/site-packages/pendulum/parsing/__init__.py", line 74, in parse return _normalize(_parse(text, **_options), **_options) ^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/admin/.virtualenvs/msgraph/lib/python3.11/site-packages/pendulum/parsing/__init__.py", line 115, in _parse return _parse_iso8601_interval(text) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/admin/.virtualenvs/msgraph/lib/python3.11/site-packages/pendulum/parsing/__init__.py", line 225, in _parse_iso8601_interval elif last[0] == "P": ~~~~^^^ ```
Spaider commented 11 months ago

I think there's a simple fix for this:

File kiota_serialization_json/json_parse_node.py, line 303. This:

            try:
                datetime_obj = pendulum.parse(value)
                if isinstance(datetime_obj, pendulum.Duration):
                    return datetime_obj.as_timedelta()
                return datetime_obj
            except ValueError:
                pass

should be changed to this:

            try:
                datetime_obj = pendulum.parse(value)
                if isinstance(datetime_obj, pendulum.Duration):
                    return datetime_obj.as_timedelta()
                return datetime_obj
            except (ValueError, IndexError):
                pass
handokoaji commented 10 months ago

me too with same error

Traceback (most recent call last):
  File "/home/airflow/.local/lib/python3.8/site-packages/airflow/models/taskinstance.py", line 433, in _execute_task
    result = execute_callable(context=context, **execute_callable_kwargs)
  File "/home/airflow/.local/lib/python3.8/site-packages/airflow/operators/python.py", line 199, in execute
    return_value = self.execute_callable()
  File "/home/airflow/.local/lib/python3.8/site-packages/airflow/operators/python.py", line 216, in execute_callable
    return self.python_callable(*self.op_args, **self.op_kwargs)
  File "/opt/airflow/dags/planner_task_dag.py", line 193, in run_save_task
    loop.run_until_complete(get_task(row[0], row[1]))
  File "/usr/local/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
    return future.result()
  File "/opt/airflow/dags/planner_task_dag.py", line 80, in get_task
    data = await client.planner.plans.by_planner_plan_id('HyBRAmsrYEeIU5mizoiLGMgAD_On').tasks.get()
  File "/home/airflow/.local/lib/python3.8/site-packages/msgraph/generated/planner/plans/item/tasks/tasks_request_builder.py", line 66, in get
    return await self.request_adapter.send_async(request_info, PlannerTaskCollectionResponse, error_mapping)
  File "/home/airflow/.local/lib/python3.8/site-packages/kiota_http/httpx_request_adapter.py", line 192, in send_async
    value = root_node.get_object_value(parsable_factory)
  File "/home/airflow/.local/lib/python3.8/site-packages/kiota_serialization_json/json_parse_node.py", line 212, in get_object_value
    self._assign_field_values(result)
  File "/home/airflow/.local/lib/python3.8/site-packages/kiota_serialization_json/json_parse_node.py", line 281, in _assign_field_values
    field_deserializer(JsonParseNode(field_value))
  File "/home/airflow/.local/lib/python3.8/site-packages/msgraph/generated/models/planner_task_collection_response.py", line 40, in <lambda>
    "value": lambda n : setattr(self, 'value', n.get_collection_of_object_values(PlannerTask)),
  File "/home/airflow/.local/lib/python3.8/site-packages/kiota_serialization_json/json_parse_node.py", line 163, in get_collection_of_object_values
    return list(
  File "/home/airflow/.local/lib/python3.8/site-packages/kiota_serialization_json/json_parse_node.py", line 165, in <lambda>
    lambda x: self._create_new_node(x).get_object_value(factory),  # type: ignore
  File "/home/airflow/.local/lib/python3.8/site-packages/kiota_serialization_json/json_parse_node.py", line 212, in get_object_value
    self._assign_field_values(result)
  File "/home/airflow/.local/lib/python3.8/site-packages/kiota_serialization_json/json_parse_node.py", line 281, in _assign_field_values
    field_deserializer(JsonParseNode(field_value))
  File "/home/airflow/.local/lib/python3.8/site-packages/msgraph/generated/models/planner_task.py", line 116, in <lambda>
    "assignments": lambda n : setattr(self, 'assignments', n.get_object_value(PlannerAssignments)),
  File "/home/airflow/.local/lib/python3.8/site-packages/kiota_serialization_json/json_parse_node.py", line 212, in get_object_value
    self._assign_field_values(result)
  File "/home/airflow/.local/lib/python3.8/site-packages/kiota_serialization_json/json_parse_node.py", line 283, in _assign_field_values
    item_additional_data[field_name] = self.try_get_anything(field_value)
  File "/home/airflow/.local/lib/python3.8/site-packages/kiota_serialization_json/json_parse_node.py", line 296, in try_get_anything
    return dict(map(lambda x: (x[0], self.try_get_anything(x[1])), value.items()))
  File "/home/airflow/.local/lib/python3.8/site-packages/kiota_serialization_json/json_parse_node.py", line 296, in <lambda>
    return dict(map(lambda x: (x[0], self.try_get_anything(x[1])), value.items()))
  File "/home/airflow/.local/lib/python3.8/site-packages/kiota_serialization_json/json_parse_node.py", line 299, in try_get_anything
    datetime_obj = pendulum.parse(value)
  File "/home/airflow/.local/lib/python3.8/site-packages/pendulum/parser.py", line 29, in parse
    return _parse(text, **options)
  File "/home/airflow/.local/lib/python3.8/site-packages/pendulum/parser.py", line 45, in _parse
    parsed = base_parse(text, **options)
  File "/home/airflow/.local/lib/python3.8/site-packages/pendulum/parsing/__init__.py", line 74, in parse
    return _normalize(_parse(text, **_options), **_options)
  File "/home/airflow/.local/lib/python3.8/site-packages/pendulum/parsing/__init__.py", line 115, in _parse
    return _parse_iso8601_interval(text)
  File "/home/airflow/.local/lib/python3.8/site-packages/pendulum/parsing/__init__.py", line 225, in _parse_iso8601_interval
    elif last[0] == "P":
IndexError: string index out of range

how to fix this ?

handokoaji commented 10 months ago

I think there's a simple fix for this:

File kiota_serialization_json/json_parse_node.py, line 303. This:

            try:
                datetime_obj = pendulum.parse(value)
                if isinstance(datetime_obj, pendulum.Duration):
                    return datetime_obj.as_timedelta()
                return datetime_obj
            except ValueError:
                pass

should be changed to this:

            try:
                datetime_obj = pendulum.parse(value)
                if isinstance(datetime_obj, pendulum.Duration):
                    return datetime_obj.as_timedelta()
                return datetime_obj
            except (ValueError, IndexError):
                pass

i'm using docker compose, how to fix this in docker ?

KirieLah commented 8 months ago

i think this is fixed in the latest release of microsoft-kiota-serialization-json they seem to just accept everything now instead of throwing an error

andrueastman commented 7 months ago

@Spaider Any chance you can confirm this is fixed in the latest version of the python SDK?

Spaider commented 7 months ago

@andrueastman I'll try to test it as soon as I can. Our old tenant seems to be turned off already. Need to come up with other way to get "real" data.

Spaider commented 7 months ago

@andrueastman yes, this bug has been fixed.

andrueastman commented 7 months ago

Thanks for confirming! Closing this one for now