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

Fedex Tracker erroring with an inconsistent date format #654

Closed
ChrisNolan opened this issue Aug 23, 2024 Discussed in #650 · 4 comments
Closed

Fedex Tracker erroring with an inconsistent date format #654

ChrisNolan opened this issue Aug 23, 2024 Discussed in #650 · 4 comments

Comments

@ChrisNolan
Copy link
Contributor

ChrisNolan commented Aug 23, 2024

The logic is here

def _extract_details(
    result: dict,
    settings: provider_utils.Settings,
) -> typing.Optional[models.TrackingDetails]:
    package = lib.to_object(tracking.CompleteTrackResultType, result)
    detail = max(
        package.trackResults,
        key=lambda item: max(
            lib.to_date(event.date, "%Y-%m-%dT%H:%M:%S%z") for event in item.scanEvents
        ),
        default=None,
    )

One possible 'hack' to force the data into the format would be something like

       key=lambda item: max(
            lib.to_date(
                event.date + "+0000" if "Z" not in event.date and "+" not in event.date and "-" not in event.date[-5:] else event.date, 
                "%Y-%m-%dT%H:%M:%S%z"
            ) for event in item.scanEvents
        )

but having a function of some sort that could possibly consistently handle differently formatted dates might be a more robust solution?

Here is a tracking number which has the issue with the "PU" (Pickup Event).

And to be complete, this is the result that karrio actually gives as it doesn't fail outright

{"messages"=>[{"carrier_id"=>"fedex-ca-tracking", "carrier_name"=>"fedex", "code"=>"SHIPPING_SDK_INTERNAL_ERROR", "message"=>"time data '2024-08-15T00:00:00' does not match format '%Y-%m-%dT%H:%M:%S%z'"}]}

Discussed in https://github.com/orgs/karrioapi/discussions/650

Originally posted by ChrisNolan August 22, 2024
I have a bunch of tracking numbers from Fedex atm who are returning poorly formatted dates which Karrio is not able to handle atm.

In people's opinions, how should Karrio handle this do you think?

In this case for example Fedex is giving "date": "2024-08-15T00:00:00", when the code is expecting a timezone to be included -- e.g.
lib.to_date(event.date, "%Y-%m-%dT%H:%M:%S%z") for event in item.scanEvents

I think it is a weird issue with a device in one of our warehouses that is causing it, but I'm not sure. But it means a bunch of tracking numbers can't be added in the mean time, and before I 'hack' it up too much myself, I thought I'd ask people's opinions on 'best practices' for handling it?

Should I just add in a timezone if it is missing (and if so, go with "+0000" (or is it -0000), or try to 'infer' a timezone from neighbouring 'events' or something else in the 'header'. Or should I more gracefully 'skip' that event, and if I skip the event, should I inject an event into the history saying that there was a missing event? Or some combination of thsoe, or something else entirely?

Thanks for your time. (Note I did email hello@karrio.io as well, sorry for the duplication)

@danh91
Copy link
Member

danh91 commented Aug 24, 2024

Hi @ChrisNolan,
I pushed a fix on the 2024.6-rc31 release. Please try it out when you get a chance.

Here is what the code looks like:

DATETIME_FORMATS = ["%Y-%m-%dT%H:%M:%S%z", "%Y-%m-%dT%H:%M:%S"]

detail = max(
package.trackResults,
key=lambda item: max(
lib.to_date(event.date, try_formats=DATETIME_FORMATS).replace(tzinfo=None)
for event in item.scanEvents
),
default=None,
)

I am going to close this for now.

@danh91 danh91 closed this as completed Aug 24, 2024
@ChrisNolan
Copy link
Contributor Author

Excellent, thank you! I'll update this afternoon and let you know if there is any issue with it. Cheers.

@ChrisNolan
Copy link
Contributor Author

Hey @danh91 I'm still pretty new at all this... it doesn't seem like the rc31 has an image available via docker. Is that correct? Is there a step that is missed, should it be automatic or something else?
I found this command to list me all the available images and rc30 is there, but not rc31?
skopeo list-tags docker://karrio.docker.scarf.sh/karrio/server|grep 2024.6-rc3

It looks like I can just 'build' my own image if I clone the repo... is that what I should do? Up to this point I was just editting my docker-compose.yml and changing the 'image' line.

Thanks for any tips.

@danh91
Copy link
Member

danh91 commented Aug 26, 2024

Hi @ChrisNolan ,

It is fully automated with Github actions. I somehow didn't push the updated version file required to trigger the build.

Done now.

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

No branches or pull requests

3 participants
@ChrisNolan @danh91 and others