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

[BUG] get_trips triggers an exception when connections do not have a duration set #52

Closed
chrrel opened this issue May 27, 2022 · 2 comments · Fixed by #53
Closed

[BUG] get_trips triggers an exception when connections do not have a duration set #52

chrrel opened this issue May 27, 2022 · 2 comments · Fixed by #53
Assignees
Labels
bug Something isn't working

Comments

@chrrel
Copy link

chrrel commented May 27, 2022

Describe the bug
The method get_trips triggers an exception upon retrieving a trip that contains a connection that does not have the connection.duration attribute set.

Apparently, the VVS API does not set the duration property in case a connection takes less than a minute, i.e. the duration would be 0. This is at least what I assume to be reason for not adding the duration.

Expected behavior
The request should not fail. If no duration is given, it probably is 0 and thus does not need to be part of the final sum.

Proof of Concept
The following request is one that triggers the exception. One part of the trip contains a connection with only one stop, taking less than a minute.

from vvspy import get_trips
from datetime import datetime

trip = get_trips("de:08111:341", "de:08111:6118", trip_date=datetime(2022, 8, 1, 10, 15, 0, 0))
print(trip)

Code fragment

The problematic code can be found in https://github.com/zaanposni/vvspy/blob/master/vvspy/obj/trip.py#L33:

    def __init__(self, **kwargs):
        self.connections = []
        for connection in kwargs.get("legs", []):
            self.connections.append(Connection(**connection))

        self.duration = sum([x.duration for x in self.connections])

Suggestion
It has to be checked whether the duration attribute exists. If it does not exist, (I assume that) it is equal to 0 and therefore can be left out.

        self.duration = sum([x.duration for x in self.connections if x.duration])
@zaanposni
Copy link
Owner

zaanposni commented May 27, 2022

Hi @chrrel
I have uploaded the new version (1.1.4) to pypi.
I have added you as a contributor to the readme file, I hope this is ok with you.

Thank you for your detailed report and the quick fix 😄

Edited: the vvs api is weird sometimes...

@chrrel
Copy link
Author

chrrel commented May 27, 2022

Thanks, @zaanposni. That was really fast!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants