squidfunk / mkdocs-material

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

Blog Plugin still errors with TypeError: can't compare offset-naive and offset-aware datetimes #7748

Open Andre601 opened 4 days ago

Andre601 commented 4 days ago

Context

Continuation of #7725 which seems to still be present.

Bug description

When executing a build does the build error with TypeError: can't compare offset-naive and offset-aware datetime

Full Stacktrace from mkdocs build:

$ mkdocs build
INFO    -  Cleaning site directory
INFO    -  Building documentation to directory: D:\GitHub\reproduction\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 "D:\GitHub\reproduction\venv\Scripts\mkdocs.exe\__main__.py", line 7, in <module>
  File "D:\GitHub\reproduction\venv\Lib\site-packages\click\core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\GitHub\reproduction\venv\Lib\site-packages\click\core.py", line 1078, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "D:\GitHub\reproduction\venv\Lib\site-packages\click\core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\GitHub\reproduction\venv\Lib\site-packages\click\core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\GitHub\reproduction\venv\Lib\site-packages\click\core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\GitHub\reproduction\venv\Lib\site-packages\mkdocs\__main__.py", line 288, in build_command
    build.build(cfg, dirty=not clean)
  File "D:\GitHub\reproduction\venv\Lib\site-packages\mkdocs\commands\build.py", line 292, in build
    files = config.plugins.on_files(files, config=config)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\GitHub\reproduction\venv\Lib\site-packages\mkdocs\plugins.py", line 593, in on_files
    return self.run_event('files', files, config=config)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\GitHub\reproduction\venv\Lib\site-packages\mkdocs\plugins.py", line 566, in run_event
    result = method(item, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^
  File "D:\GitHub\reproduction\venv\Lib\site-packages\material\plugins\blog\plugin.py", line 133, in on_files
    self.blog.posts = sorted(
                      ^^^^^^^
  File "D:\GitHub\reproduction\venv\Lib\site-packages\material\plugins\blog\plugin.py", line 444, in _resolve_posts
    if not self._is_excluded(post):
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\GitHub\reproduction\venv\Lib\site-packages\material\plugins\blog\plugin.py", line 373, in _is_excluded
    return post.config.date.created > datetime.now()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: can't compare offset-naive and offset-aware datetimes

The issue is most likely the usage of date: yyyy-mm-dd without any timezones or time in general.

Note: Only mkdocs build is affected. mkdocs serve runs without any errors reported.

Related links

Reproduction

9.5.46-blog-date-issue.zip

Steps to reproduce

  1. Install Material for MkDocs 9.5.46
  2. Setup Blog plugin
  3. Create a post with a date frontmatter in the format yyyy-mm-dd
  4. Execute mkdocs build

Browser

No response

Before submitting

squidfunk commented 4 days ago

Thanks for reporting. Help appreciated! It's likely the same fix as for #7725. I did not expect this to be such a nuisance to fix. I'm currently short on time, so if anybody has a few minutes on his hands, PR appreciated.

perpil commented 4 days ago

Working on a fix, it appears with draft_if_future_date: true it is still using non timezone aware dates.

perpil commented 3 days ago

PR #7749 out and tested against the repro. I've looked for other instances of datetime and think I've finally got them all.

squidfunk commented 3 days ago

Keeping open until released.