Skip to content

SharePoint Custom Fields (Single line of text) - Gets cast to Python Pendulam DateTime #653

Closed
microsoft/kiota-serialization-json-python
#348

Description

@nikhilmakan02

Hi Everyone, doing a simple call to a SharePoint Document library to return the custom metadata fields related to a file. What's interesting is I can set the column type to 'Single line of text' in SharePoint but if I put certain numbers into the column it returns as a datetime object.

If I put text in the field on SharePoint it returns correctly as text or even if I put enough numbers it returns as text as well.

In the example below the Doc_ID column in SharePoint contains the numbers 1212.
image
image

result = await (
        client.drives.by_drive_id(drive_id)
        .items.by_drive_item_id(drive_item_id)
        .list_item.get()
    )

print(result.fields.additional_data["Doc_x0020_ID"])
print(type(result.fields.additional_data["Doc_x0020_ID"]))

Output:

1212-01-01 00:00:00+00:00
<class 'pendulum.datetime.DateTime'>

This seems like unexpected behavior?

Activity

  1. georgethomasii commented on Apr 8, 2024

    @georgethomasii

    I am seeing a similar issues when querying entraid attributes. Any value that has a 4-digit numerical value is being returned as a datetime object instead of a string. If I get the raw http response the value is returned as a string correctly. It would be great if this was looked into and resolved as I prefer not to have to get the native HTTPX response.

  2. added
    area:serializationFocused on functional modules of the product
    priority:p2Medium. For a p2 bug, generally have a work-around. Bug SLA <=30 days
    on Apr 23, 2024
  3. shemogumbe commented on Apr 23, 2024

    @shemogumbe
    Contributor

    Hello, and thanks for continued use of the SDK and for raising this.
    As we look into our serialization to give a consistent behaviour, would you cast the result to a string/datetime object for now:

    • Pendulum to string
    # Cast Pendulum DateTime to string
    pendulum_datetime_string = pendulum_datetime.to_iso8601_string()
    print("Pendulum DateTime as string (ISO 8601 format):", pendulum_datetime_string)
    • string to pendulum
    # Parse the string to Pendulum DateTime object
    pendulum_datetime = pendulum.parse(pendulum_datetime_if_string)
  4. nikhilmakan02 commented on Apr 23, 2024

    @nikhilmakan02
    Author

    Shem Ogumbe (@shemogumbe) I am not really sure how that is helpful? Are you suggesting I cast this to a string then truncate the string to get the 4 digit value. That sounds like a messy solution to be honest.

    I have actually just implemented georgethomasii suggestion to just get the raw response and get the metadata more reliably there.

  5. added
    priority:p0Blocking issue. Loss of critical functions eg security/privacy violation. Bug SLA<=48hrs
    and removed
    priority:p2Medium. For a p2 bug, generally have a work-around. Bug SLA <=30 days
    on Aug 23, 2024
  6. 56badkarma commented on Aug 19, 2026

    @56badkarma

    Anyone still dealing with this issue:
    microsoft/kiota-python/pull/664
    merged and released last week. Latest version has the real fix.

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

Metadata

Metadata

Labels

area:serializationFocused on functional modules of the productbugSomething isn't workingpriority:p0Blocking issue. Loss of critical functions eg security/privacy violation. Bug SLA<=48hrs

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions