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

Avoid infinite loop in Datetime.bulk_create_datetimes by checking for positive timedelta #1229

Merged

Conversation

Wooza
Copy link
Contributor

@Wooza Wooza commented Jun 22, 2022

Hi,

we were evaluating our automated unit test generator on mimesis and found a bug in Datetime.bulk_create_datetimes. It is possible to call this method without **kwargs or with **kwargs that represent a non-positive timedelta. In such a case, the while loop in this method never terminates. I have added a simple check to verify that the used timedelta is positive and also added a test case for it.

Checklist

  • I have read contributing guidelines

  • I'm sure that I did not unrelated changes in this pull request

  • I have created at least one test case for the changes I have made

  • I have added myself to the CONTRIBUTORS.rst

Best regards
Florian

@codecov
Copy link

codecov bot commented Jun 22, 2022

Codecov Report

Merging #1229 (8551005) into master (5a89f7d) will decrease coverage by 0.09%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master    #1229      +/-   ##
==========================================
- Coverage   98.89%   98.79%   -0.10%     
==========================================
  Files          57       57              
  Lines        1988     1990       +2     
==========================================
  Hits         1966     1966              
- Misses         22       24       +2     

@@ -45,6 +45,11 @@ def test_bulk_create_datetimes_error(self, _datetime):
with pytest.raises(ValueError):
_datetime.bulk_create_datetimes(None, None)

with pytest.raises(ValueError):
Copy link
Owner

Choose a reason for hiding this comment

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

I don't get it. Why error should raise here if timedelta is positive in this particular case?

Copy link
Owner

Choose a reason for hiding this comment

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

Oh, I get it. It just incrementing date_start by timedelta(0) that make no sense.

@lk-geimfari
Copy link
Owner

@Wooza Thank you! This is a major bug actually. I'll publish new version ASAP.

@lk-geimfari lk-geimfari merged commit 523d22f into lk-geimfari:master Jun 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants