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

When attempting to generate a Finnish ssn of a specific age the provider crashes #1936

Closed
Pakkanen1 opened this issue Oct 20, 2023 · 2 comments · Fixed by #1937
Closed

When attempting to generate a Finnish ssn of a specific age the provider crashes #1936

Pakkanen1 opened this issue Oct 20, 2023 · 2 comments · Fixed by #1937

Comments

@Pakkanen1
Copy link
Contributor

  • Faker version: 19.11.0
  • OS: Windows 10

When attempting to generate a Finnish ssn of a certain age the provider crashes because datetime.timedelta(days=self.generator.random.randrange(min_age * 365, max_age * 365)) is always trying to generate a time within range. The ssn provider should handle situations where min_age and max_age are the same.
For example:

if min_age == max_age:
    age = datetime.timedelta(days=min_age * 365)
else:
    age = datetime.timedelta(days=self.generator.random.randrange(min_age * 365, max_age * 365))

Steps to reproduce

  1. Create a faker with fi_FI locale: fake = Faker('fi_FI')
  2. Call the ssn provider with the same minimum and maximum age: fake.ssn(min_age=50, max_age=50, artificial=True)

Expected behavior

The faker generates an artificial Finnish ssn that is 50 years old.

Actual behavior

ValueError: empty range for randrange() (18250, 18250, 0)

@stefan6419846
Copy link
Contributor

Do you want to submit a corresponding PR including a test to ensure that this is handled correctly?

@Pakkanen1
Copy link
Contributor Author

Do you want to submit a corresponding PR including a test to ensure that this is handled correctly?

Sure. Here it is: #1937

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 a pull request may close this issue.

2 participants