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

fix: timedelta parsing for int and floats #368

Closed
wants to merge 1 commit into from

Conversation

tcleonard
Copy link

@tcleonard tcleonard commented Nov 15, 2024

Version 11.2.0 introduced a regression when it comes to providing timedelta as floats or integers.

toto = env.timedelta("TOTO", default=30)   # does not works
toto = env.timedelta("TOTO", default=30.0)   # does not works
toto = env.timedelta("TOTO", default="30")   # works
toto = env.timedelta("TOTO", default="30.")   # does not works

This MR aims at making those 4 cases valid

milliseconds=int(match.group(6) or 0),
microseconds=int(match.group(7) or 0),
seconds=seconds,
milliseconds=milliseconds,
)
return super()._deserialize(value, *args, **kwargs)
Copy link
Contributor

@ddelange ddelange Nov 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like a lot of logic was added just to bypass the parent class' validation (this line won't be hit anymore).

  • a float as default value was previously slipping through the cracks (silent downcast to int before #366, a bug not a feature imo)
  • a float-in-string as default value didn't slip through the cracks (expected behaviour to reject)

is this PR something that should rather fold into the bigger topic of #270 and/or #297 instead?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

opened a minimal version to avoid breaking change: #369

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(this line won't be hit anymore).

It will if you provide something that is of other type than str, float, int, bool, timedelta.
So this is more a last option catch-all.

We could definitely do the more minimal change to get to the previously working (but unconsistent/unlogical behavior)... but I'm not sure what's wrong with this PR which supports the previously working pattern and actually fixes some of the inconsistent behaviors?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and actually, I think that #297 is not relevant anymore as it was already fixed (prior to this PR)

@sloria
Copy link
Owner

sloria commented Nov 20, 2024

merged solution in #369

@sloria sloria closed this Nov 20, 2024
@tcleonard
Copy link
Author

tcleonard commented Nov 20, 2024

Sorry but I don't understand why this is closed @sloria . The other PR solves the breaking change that was introduced... but it persist the inconsistent behavior from before.
You can take the tests written in this PR and run them against the released version and you will see that it fails.

So why close this proposal of an alternative that makes the overall user experience better?

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

Successfully merging this pull request may close these issues.

3 participants