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

OSError: [Errno 22] Invalid argument on Windows #829

Closed
ricosuave73 opened this issue Oct 4, 2018 · 11 comments · Fixed by #1436
Closed

OSError: [Errno 22] Invalid argument on Windows #829

ricosuave73 opened this issue Oct 4, 2018 · 11 comments · Fixed by #1436

Comments

@ricosuave73
Copy link

In some cases random dates generated by faker fail on Windows.
There was another issue on this, but it was closed and a stack trace was asked. It was issue #460
I have the stack trace included.
Unfortunately I don't have the exact line where it fails, because there are several in my code, and the stack trace doesn't say which statement is the direct cause, but here are all of the fake dates in my code:

dateofbirth = factory.Faker('date_between', start_date="-70y", end_date="-20y")
created = factory.Faker('date_time_this_decade', before_now=True, after_now=False)
dateLastModified = factory.Faker('date_time_this_year', before_now=True, after_now=False)
password_changed = factory.Faker('date_time_this_year', before_now=True, after_now=False)
status_date = factory.Faker('date_time_this_year', before_now=True, after_now=False)

Steps to reproduce

This occurs randomly, propably when the randomly chosen date is out of specific bounds.
Please refer to #460 for further details.

Expected behavior

A random date should be assigned

Actual behavior

OSError: [Errno 22] Invalid argument

stack trace

  File "C:\projects\clubassistant\features\current\ca5\tests\businesslogic\reminderlogic.py", line 20, in test_amount_too_high_ok
    member = MemberFactory()
  File "C:\projects\clubassistant\features\current\ca5\.venv\lib\site-packages\factory\base.py", line 46, in __call__
    return cls.create(**kwargs)
  File "C:\projects\clubassistant\features\current\ca5\.venv\lib\site-packages\factory\base.py", line 563, in create
    return cls._generate(enums.CREATE_STRATEGY, kwargs)
  File "C:\projects\clubassistant\features\current\ca5\.venv\lib\site-packages\factory\base.py", line 500, in _generate
    return step.build()
  File "C:\projects\clubassistant\features\current\ca5\.venv\lib\site-packages\factory\builder.py", line 272, in build
    step.resolve(pre)
  File "C:\projects\clubassistant\features\current\ca5\.venv\lib\site-packages\factory\builder.py", line 221, in resolve
    self.attributes[field_name] = getattr(self.stub, field_name)
  File "C:\projects\clubassistant\features\current\ca5\.venv\lib\site-packages\factory\builder.py", line 375, in __getattr__
    extra=context,
  File "C:\projects\clubassistant\features\current\ca5\.venv\lib\site-packages\factory\faker.py", line 56, in evaluate
    return self.generate(extra or {})
  File "C:\projects\clubassistant\features\current\ca5\.venv\lib\site-packages\factory\faker.py", line 53, in generate
    return subfaker.format(self.provider, **kwargs)
  File "C:\projects\clubassistant\features\current\ca5\.venv\lib\site-packages\faker\generator.py", line 76, in format
    return self.get_formatter(formatter)(*args, **kwargs)
  File "C:\projects\clubassistant\features\current\ca5\.venv\lib\site-packages\faker\providers\date_time\__init__.py", line 1580, in date_between
    return self.date_between_dates(date_start=start_date, date_end=end_date)
  File "C:\projects\clubassistant\features\current\ca5\.venv\lib\site-packages\faker\providers\date_time\__init__.py", line 1680, in date_between_dates
    return self.date_time_between_dates(date_start, date_end).date()
  File "C:\projects\clubassistant\features\current\ca5\.venv\lib\site-packages\faker\providers\date_time\__init__.py", line 1665, in date_time_between_dates
    pick = datetime.fromtimestamp(timestamp, tzlocal())
OSError: [Errno 22] Invalid argument
@Mattwmaster58
Copy link

Mattwmaster58 commented Dec 12, 2018

Anything < -(datetime.now().year - 1970) will cause this error. Proof:
Try fake.date_between(start_date="-48y", end_date="today")
Now try fake.date_between(start_date="-49y", end_date="today")

The second one will invariably fail.

I haven't looked into it, but maybe this could be re-implemented by subtracting a timedelta from the start day. Thoughts?

fcurella added a commit that referenced this issue Dec 12, 2018
fcurella added a commit that referenced this issue Dec 12, 2018
@fcurella
Copy link
Collaborator

fcurella commented Dec 12, 2018

Hi @Mattwmaster58 ,

What version of Python and what version/architecture of Windows are you using?

fcurella added a commit that referenced this issue Dec 12, 2018
@fcurella
Copy link
Collaborator

I've created a branch that tests .date_between(start_date="-49y", end_date="today") at #881.

The build is passing on appveyor https://ci.appveyor.com/project/joke2k/faker/builds/20961012, so we'll need more detail about your system in order to find a way to reproduce this bug.

@Mattwmaster58
Copy link

Mattwmaster58 commented Dec 12, 2018 via email

@fcurella
Copy link
Collaborator

@Mattwmaster58 I'm assuming 64 bit architecture?

fcurella added a commit that referenced this issue Dec 12, 2018
@fcurella
Copy link
Collaborator

@Mattwmaster58 AppVeyor can test under Windows Server 2012 R2 or Windows Server 2016 (https://www.appveyor.com/docs/windows-images-software/#operating-system), but not on Windows 10.

The first step is to add Windows 10 to our CI infrastructure somehow, so that we can actually reproduce the bug now and for the future.

@Mattwmaster58
Copy link

Mattwmaster58 commented Dec 12, 2018 via email

@Mattwmaster58
Copy link

This almost works, but timezones strike again (The expected result is 7 hours off, my timezone is UTC-7:00)
(code from inside date_time_between_dates)

pick = datetime_end - self.generator.random.randint(0, datetime_to_timestamp(datetime_end) - datetime_to_timestamp(datetime_start))

I don't really see another straighforward approach when datetime.fromtimestamp doesn't accept negative values on some systems.

@Loucool111
Copy link

As of Nov 11, 2020, I'm still running into the same issue with Windows 10 2003 with Python 3.9.0 and faker 4.14.2

How do you suggest I fix this in the meantime?

@Mattwmaster58
Copy link

@Loucool111 It's been a while since I've worked with the lib, but maybe play around with my suggestion above and get something that is timezone agnostic. Once you get that down submit a PR.

@mrshu
Copy link

mrshu commented Jan 2, 2021

This is a wild guess, but having ran into this issue while debugging an unrelated project [0], I am wondering whether the culprit may be some characters that are not permitted as Windows filenames (such as say colons). Here is the (potentially) relevant StackOverflow answer: https://stackoverflow.com/questions/43196750/python-oserror-errno-22-invalid-argument

Cheers!

[0] robocup-junior/rcj-soccersim#40

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants