Skip to content

Date out of range error #143

Closed
Closed

Description

@sti0

According to #80 we facing the same error. We're just consumer using the api to receive data for our DWH. Currently one of our job fails because of this error.

Is it possible to implement a fix for this problem on pyodata side?

Json:

{
    "d": {
        "results": {
            "__metadata": {
                "uri": "https://service.url/sap/c4c/odata/v1/c4codataapi/CorporateAccountIdentificationCollection('12345678910111213ABCDEFGHIJKLMNO')",
                "type": "c4codata.CorporateAccountIdentification",
                "etag": "W/"datetimeoffset'2021-02-01T19%3A41%3A17.9430080Z'""
            },
            "ObjectID": "12345678910111213ABCDEFGHIJKLMNO",
            "ParentObjectID": "166345678910111213ABCDEFGHIJKLMNO",
            "ETag": "/Date(1612208477943)/",
            "AccountID": "12345",
            "IDTypeCode": "ABCDE",
            "IDTypeCodeText": "<ABCD12>",
            "IDNumber": "1234-123",
            "ResponsibleInstitution": "",
            "EntryDate": null,
            "ValidFrom": "/Date(-62135769600000)/",
            "ValidTo": "/Date(253402214400000)/",
            "CountryCode": "",
            "CountryCodeText": "",
            "StateCode": "",
            "StateCodeText": "",
            "ZZWECK_KUT": "",
            "ZZWECK_KUTText": "",
            "CorporateAccount": {
                "__deferred": {
                    "uri": "https://service.url/sap/c4c/odata/v1/c4codataapi/CorporateAccountIdentificationCollection('12345678910111213ABCDEFGHIJKLMNO')/CorporateAccount"
                }
            }
        }
    }
}

Thanks & BR

Activity

  1. filak-sap commented on Feb 8, 2021

    @filak-sap
    Contributor

    Well, we can for sure add a workaround (a global variable or something like that) which would cause that any value lower than -62135769600000 would be resolved as 1970-01-01T00:00:00. We haven't added it yet as one of the goals of PyOdata is to test OData service implementation and the value in your case is clearly wrong.

    Feel free to open a PR. I would create a global variable in https://github.com/SAP/python-pyodata/blob/master/pyodata/v2/model.py which would enable a new test in at

    value = datetime.datetime(1970, 1, 1, tzinfo=current_timezone()) + datetime.timedelta(milliseconds=int(value))

    value_microseconds = int(value)
    if FIX_SCREWED_UP_MINIMAL_DATETIME_VALUE and value < -62135769600000:
        return datetime.datetime(year=1, day=1, month=1)

    or something like that - it needs to be clearly documented and the error meessage at

    raise PyODataModelError('Cannot decode datetime from value {}.'.format(value))
    should provide a hint.

    Please, add also test case.

  2. added a commit that references this issue on Mar 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions