squidfunk / mkdocs-material

Documentation that simply works
https://squidfunk.github.io/mkdocs-material/
MIT License
21.16k stars 3.57k forks source link

Blog plugin failing with TypeError: can't compare offset-naive and offset-aware datetimes on 9.5.45 #7725

Closed mvelikikh closed 2 days ago

mvelikikh commented 1 week ago

Context

No response

Bug description

mkdocs build --strict fails on 9.5.45 with the error below:

mkdocs build -s
INFO    -  Cleaning site directory
INFO    -  Building documentation to directory: D:\temp\20241120\mkdocs\site
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "C:\Users\Mikhail\AppData\Local\Programs\Python\Python312\Scripts\mkdocs.exe\__main__.py", line 7, in <module>
  File "C:\Users\Mikhail\AppData\Local\Programs\Python\Python312\Lib\site-packages\click\core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Mikhail\AppData\Local\Programs\Python\Python312\Lib\site-packages\click\core.py", line 1078, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "C:\Users\Mikhail\AppData\Local\Programs\Python\Python312\Lib\site-packages\click\core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Mikhail\AppData\Local\Programs\Python\Python312\Lib\site-packages\click\core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Mikhail\AppData\Local\Programs\Python\Python312\Lib\site-packages\click\core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Mikhail\AppData\Local\Programs\Python\Python312\Lib\site-packages\mkdocs\__main__.py", line 288, in build_command
    build.build(cfg, dirty=not clean)
  File "C:\Users\Mikhail\AppData\Local\Programs\Python\Python312\Lib\site-packages\mkdocs\commands\build.py", line 292, in build
    files = config.plugins.on_files(files, config=config)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Mikhail\AppData\Local\Programs\Python\Python312\Lib\site-packages\mkdocs\plugins.py", line 593, in on_files
    return self.run_event('files', files, config=config)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Mikhail\AppData\Local\Programs\Python\Python312\Lib\site-packages\mkdocs\plugins.py", line 566, in run_event
    result = method(item, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Mikhail\AppData\Local\Programs\Python\Python312\Lib\site-packages\material\plugins\blog\plugin.py", line 133, in on_files
    self.blog.posts = sorted(
                      ^^^^^^^
TypeError: can't compare offset-naive and offset-aware datetimes

9.5.38 works fine. I constructed a minimal reproduction test case, and based on this, the error is thrown when I have two formats of date.created:

  1. yyyy-mm-dd (e.g. created: 2024-09-06)
  2. yyyy-mm-ddThh:mi:ss (e.g. created: 2019-02-25T04:25:00)

Both formats are supported per the documentation: https://squidfunk.github.io/mkdocs-material/plugins/blog/#meta.date

If I remove any of the files and keep only one format, there is no error.

Related links

Reproduction

9.5.45-typerror-cannot-compare-datetimes.zip

Steps to reproduce

  1. pip install . (the reproduction file has pyproject.toml)
  2. mkdocs build --strict - should fail ❌
  3. pip install mkdocs-material==9.5.38
  4. mkdocs build --strict - should work✔

Browser

Firefox

Before submitting

perpil commented 1 week ago

I've got a PR to address this here: #7730

As a temporary workaround if you add a timezone i.e. -07:00 or Z to the end of your dates that have a time, that should get you unblocked.

mvelikikh commented 1 week ago

The workaround I use now is to use 9.5.38. Another workaround is to use dates with time because most of my dates are with times, and only one is yyyy-mm-dd which is causing issues in 9.5.45 that broke it. There is no need for a time zone because I don't use it. It is not in the documentation either: https://squidfunk.github.io/mkdocs-material/plugins/blog/#meta.date

squidfunk commented 1 week ago

@mvelikikh #7730 is merged. Could you please check if the error is fixed for you now?

perpil commented 1 week ago

The workaround I use now is to use 9.5.38. Another workaround is to use dates with time because most of my dates are with times, and only one is yyyy-mm-dd which is causing issues in 9.5.45 that broke it. There is no need for a time zone because I don't use it. It is not in the documentation either: https://squidfunk.github.io/mkdocs-material/plugins/blog/#meta.date

Thanks @mvelikikh your workaround is the correct one. Sorry for the churn here, I believe #7730 should address all cases.

mvelikikh commented 1 week ago

@squidfunk I tested and can confirm that it works with the latest changes from https://github.com/squidfunk/mkdocs-material/commit/eee4934efdf21f6d3bc576afd02a63cf96485299 @perpil thanks for fixing this.

squidfunk commented 6 days ago

Thanks for your time, @perpil! I'll let that sit for 2-3 days to see if we catch another bug, and then issue the next release.

practicalli-johnny commented 5 days ago

FYI: I experienced the same issue using material for mkdocs 9.5.45 within the GtiHub action used to publish my journal.

My posts all use the yyyy-mm-dd date format.

Setting the mkdocs-material python package version to 9.5.44 in the GitHub actions workflow file resolves this issue, until the next release is available.

- run: pip install mkdocs-material=="9.5.44" mkdocs-callouts mkdocs-glightbox mkdocs-git-revision-date-localized-plugin mkdocs-redirects mkdocs-rss-plugin pillow cairosvg

Thank you for quickly creating a fix

squidfunk commented 2 days ago

Released as part of 9.5.46.

Andre601 commented 2 days ago

I'm still receiving this issue using 9.5.46.

Here's the CI run failing: https://ci.codeberg.org/repos/12442/pipeline/205/4 And here's one of the blog posts I have: https://codeberg.org/Andre601/website/src/branch/renovate/mkdocs-material-9.x/docs/blog/posts/2024/11-14-add-fediverse-creator-tag.md

Also, if it is of any importance is here the Pipeline file that is used on PRs: https://codeberg.org/Andre601/website/src/branch/renovate/mkdocs-material-9.x/.woodpecker/pr_preview.yml

This also happens locally on my PC after installing latest mkdocs-material via pip install -U -r requirements.txt, using the branch with the new version.

squidfunk commented 2 days ago

If it's the exact same issue, please create a minimal reproduction, and attach it here. If it's slightly different, please create a new issue, including a minimal reproduction of course. We let the fix sit here for two days and no further feedback was provided, so I read that as this issue is fixed now.

Andre601 commented 2 days ago

The cause is the same (TypeError: can't compare offset-naive and offset-aware datetimes), but stacktrace is different.

Will try to make a minimal reproduction here to see what the issue may be and if reproduced, file a new issue.