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

TypeError: fromisoformat: argument must be str #92

Closed
stevexiong-hennepin opened this issue Apr 10, 2024 · 6 comments · Fixed by #93
Closed

TypeError: fromisoformat: argument must be str #92

stevexiong-hennepin opened this issue Apr 10, 2024 · 6 comments · Fixed by #93
Assignees
Labels
bug Something isn't working

Comments

@stevexiong-hennepin
Copy link

Describe the bug

I'm testing this out for use. I'm getting the below error running on ubuntu-latest GitHub runner.

Traceback (most recent call last):
File "/action/workspace/evergreen.py", line 361, in
main() # pragma: no cover
^^^^^^
File "/action/workspace/evergreen.py", line 83, in main
if is_repo_created_date_before(repo.created_at, created_after_date):
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/action/workspace/evergreen.py", line 164, in is_repo_created_date_before
repo_created_at_date = datetime.fromisoformat(repo_created_at).replace(tzinfo=None)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: fromisoformat: argument must be str

To Reproduce

  1. Copied the basic example workflow from readme
  2. Updated 'Run evergreen action' step to the below
      - name: Run evergreen action
        uses: github/evergreen@v1
        env:
          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          REPOSITORY: "myorg/myrepo"
          FILTER_VISIBILITY: "private,internal"
  1. Run workflow manually through GitHub Actions page

Expected behavior

As state in readme, it open issue/PR in the specified repo.

Screenshots

No response

Additional context

I did adding env CREATED_AFTER_DATE and hardcoded "2020-01-01" as value. I got the same error.

I did see the closed issue #82, and the error appears to committed code from the pr #83 that closed that issue.

@stevexiong-hennepin stevexiong-hennepin added the bug Something isn't working label Apr 10, 2024
@jmeridth
Copy link
Member

jmeridth commented Apr 10, 2024

@stevexiong-hennepin thank you for filing this. I can take a look shortly unless you want to take a try at a PR? (Zero pressure 😄)

@jmeridth
Copy link
Member

jmeridth commented Apr 10, 2024

UPDATE

Decided to ensure the env_vars.py file returns empty string for created_after_date if the environment variable is missing, instead of None. Empty string is handled in datetime.fromisoformat and we have existing tests for that.

OLD

Fix is to add check for created_after_date to L83 of evergreen.py.

if created_after_date and is_repo_created_date_before(repo.created_at, created_after_date):
    continue

I'm afk currently but will get a PR up with a test for it and I'll do a release after it merges.

jmeridth added a commit that referenced this issue Apr 11, 2024
Fixes #92

This will handle ensure the value is never None.  If the string
does not match %Y-%m-%d format it will throw a ValueError as expected.

- [x] add tests to specifically cover case with string is 2020-01-01

Signed-off-by: jmeridth <[email protected]>
jmeridth added a commit that referenced this issue Apr 11, 2024
Fixes #92

This will handle ensure the value is never None.  If the string
does not match %Y-%m-%d format it will throw a ValueError as expected.

- [x] add tests to specifically cover case with string is 2020-01-01

Signed-off-by: jmeridth <[email protected]>
@jmeridth jmeridth self-assigned this Apr 11, 2024
@jmeridth
Copy link
Member

@stevexiong-hennepin I was unable to recreate the issue with the CREATED_AFTER_DATE env variable set to "2020-01-01". I've added explicit tests in the PR above. Can you please let me know if there was something else set? Thank you in advance.

jmeridth added a commit that referenced this issue Apr 11, 2024
Fixes #92

This will handle ensure the value is never None.  If the string
does not match %Y-%m-%d format it will throw a ValueError as expected.

- [x] add tests to specifically cover case with string is 2020-01-01

Signed-off-by: jmeridth <[email protected]>
jmeridth added a commit that referenced this issue Apr 11, 2024
…ison

Fixes #92

Stop validating created_after_date as just a 10 character string and
regex validate it as YYYY-DD-MM (where each is a digit in the string)

- [x] add tests to specifically cover case with string is 2020-01-01

Signed-off-by: jmeridth <[email protected]>
@jmeridth
Copy link
Member

@ghost
Copy link

ghost commented Apr 25, 2024

I'm experiencing the same issue, tested with both 1.9.2 and 1.10.2:

Traceback (most recent call last):
  File "/action/workspace/evergreen.py", line 371, in <module>
    main()  # pragma: no cover
    ^^^^^^
  File "/action/workspace/evergreen.py", line [9](https://github.com/<org>/<repo>/actions/runs/8831859766/job/24247946608#step:3:10)2, in main
    if is_repo_created_date_before(repo.created_at, created_after_date):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/action/workspace/evergreen.py", line 174, in is_repo_created_date_before
    repo_created_at_date = datetime.fromisoformat(repo_created_at).replace(tzinfo=None)
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: fromisoformat: argument must be str

Code:

jobs:
  evergreen:
    name: evergreen
    runs-on: ubuntu-latest
    permissions:
      issues: write

    steps:
      - name: Run evergreen action
        uses: github/[email protected]
        env:
          CREATED_AFTER_DATE: "1970-01-01" # Tested with this value and not setting it at all
          GH_TOKEN: ${{ secrets.GH_TOKEN }}
          DRY_RUN: false
          REPOSITORY: <org>/<repo>

@ghost
Copy link

ghost commented Apr 25, 2024

Testing some more, it seems like this error only appear when you specify REPOSITORY rather than ORGANIZATION.
I have not tried this with setting ORGANIZATION and DRY_RUN: false as I'd like to test it out on a single repository before I create PR for a large amount of repositories within the organization.

Edit: I'm now fairly certain this error only happens when you specify REPOSITORY. I changed it to ORGANIZATION and set a CREATED_AFTER_DATE to only include the last created repository in our organization and then this action worked fine.

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